Removed separation of nodes and sons in ir_loop
[libfirm] / ir / ana / irloop.h
1 /* Copyright (C) 2002 by Universitaet Karlsruhe
2 * All rights reserved.
3 */
4
5 /**
6 * @file irloop.h
7 *
8 *  Computes backedges in the control and data flow.
9 *
10 *  @author Goetz Lindenmaier
11 *
12 *  Only Block and Phi/Filter nodes can have incoming backedges.
13 *  Constructs loops data structure: indicates loop nesting.
14 */
15
16 /* $Id$ */
17
18 # ifndef _IRLOOP_H_
19 # define _IRLOOP_H_
20
21 # include "irgraph.h"
22 # include "irnode.h"
23
24
25 /* @@@ Interprocedural backedges ... ???? */
26
27 /*
28  * Backedge information.
29  *
30  * Predecessors of Block, Phi and interprocedural Filter nodes can
31  * have  backedges.  If loop information is computed, this
32  * information is computed, too.
33  * The backedge information can only be used if the graph is not in
34  * phase phase_building.
35  */
36
37 /** Returns true if the predesessor pos is a backedge. */
38 bool is_backedge (ir_node *n, int pos);
39 /** Remarks that edge pos is a backedge. */
40 void set_backedge (ir_node *n, int pos);
41 /** Remarks that edge pos is not a backedge. */
42 void set_not_backedge (ir_node *n, int pos);
43 /** Returns true if n has backedges. */
44 bool has_backedges (ir_node *n);
45 /** Sets backedge information to zero. */
46 void clear_backedges (ir_node *n);
47
48 /**
49  * The loops datastructure.
50  *
51  * The loops datastructure represents circles in the intermediate
52  * representation.  It does not represent loops in the terms of a
53  * source program.
54  * Each ir_graph can contain one outermost loop datastructure.
55  * loop is the entry point to the nested loops.
56  * The loop datastructure contains a field indicating the depth of
57  * the loop within the nesting.  Further it contains a list of the
58  * loops with nesting depth -1.  Finally it contains a list of all
59  * nodes in the loop.
60  *
61  * @todo We could add a field pointing from a node to the containing loop,
62  * this would cost a lot of memory, though.
63  */
64 typedef struct ir_loop ir_loop;
65
66 /* Loop elements are loop nodes and ir nodes */
67 typedef union {
68     firm_kind *kind;    /* is either k_ir_node or k_ir_loop */
69     ir_node *node;      /* Pointer to a loop tree element */
70     ir_loop *son;       /* Pointer to a ir_graph element */
71 } loop_element;
72
73 void     set_irg_loop(ir_graph *irg, ir_loop *l);
74 ir_loop *get_irg_loop(ir_graph *irg);
75
76 /** Returns the loop n is contained in.
77    assumes current_ir_graph set properly. */
78 ir_loop *get_irn_loop(ir_node *n);
79
80 /** Returns outer loop, itself if outermost. */
81 ir_loop *get_loop_outer_loop (ir_loop *loop);
82 /** Returns nesting depth of this loop */
83 int      get_loop_depth (ir_loop *loop);
84
85 /* Sons are the inner loops contained in this loop. */
86 /** Returns the number of inner loops */
87 int      get_loop_n_sons (ir_loop *loop);
88 ir_loop *get_loop_son (ir_loop *loop, int pos);
89 /** Returns the number of nodes contained in loop.  */
90 int      get_loop_n_nodes (ir_loop *loop);
91 ir_node *get_loop_node (ir_loop *loop, int pos);
92
93 /** Returns the number of elements contained in loop.  */
94 int      get_loop_n_elements (ir_loop *loop);
95 loop_element get_loop_element (ir_loop *loop, int pos);
96
97 /*
98  * Constructing and destructing the loop/backedge information.
99  */
100
101 /** Constructs backedge information for irg in intraprocedural view. */
102 void construct_backedges(ir_graph *irg);
103
104 /** Constructs backedges for all irgs in interprocedural view.  All
105    loops in the graph will be marked as such, not only realizeable
106    loops and recursions in the program.  E.g., if the same funcion is
107    called twice, there is a loop between the first funcion return and
108    the second call.  */
109 void construct_ip_backedges(void);
110
111 #endif /* _IRLOOP_H_ */