Call_callees now with unknown_entity
[libfirm] / ir / ana / irloop.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ana/irloop_t.h
4  * Purpose:     Loop datastructure and access functions.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:     7.2002
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2002-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14 * @file irloop.h
15 *
16 *  Computes backedges in the control and data flow.
17 *
18 *  @author Goetz Lindenmaier
19 *
20 *  Only Block and Phi/Filter nodes can have incoming backedges.
21 *  Constructs loops data structure: indicates loop nesting.
22 */
23
24 # ifndef _IRLOOP_H_
25 # define _IRLOOP_H_
26
27 # include "irgraph.h"
28 # include "irnode.h"
29
30
31 /* @@@ Interprocedural backedges ... ???? */
32
33 /*
34  * Backedge information.
35  *
36  * Predecessors of Block, Phi and interprocedural Filter nodes can
37  * have  backedges.  If loop information is computed, this
38  * information is computed, too.
39  * The backedge information can only be used if the graph is not in
40  * phase phase_building.
41  */
42
43 /** Returns true if the predesessor pos is a backedge. */
44 bool is_backedge (ir_node *n, int pos);
45 /** Remarks that edge pos is a backedge. */
46 void set_backedge (ir_node *n, int pos);
47 /** Remarks that edge pos is not a backedge. */
48 void set_not_backedge (ir_node *n, int pos);
49 /** Returns true if n has backedges. */
50 bool has_backedges (ir_node *n);
51 /** Sets backedge information to zero. */
52 void clear_backedges (ir_node *n);
53
54 /**
55  * The loops datastructure.
56  *
57  * The loops datastructure represents circles in the intermediate
58  * representation.  It does not represent loops in the terms of a
59  * source program.
60  * Each ir_graph can contain one outermost loop datastructure.
61  * loop is the entry point to the nested loops.
62  * The loop datastructure contains a field indicating the depth of
63  * the loop within the nesting.  Further it contains a list of the
64  * loops with nesting depth -1.  Finally it contains a list of all
65  * nodes in the loop.
66  *
67  * @todo We could add a field pointing from a node to the containing loop,
68  * this would cost a lot of memory, though.
69  */
70 typedef struct ir_loop ir_loop;
71
72 /* Loop elements are loop nodes and ir nodes */
73 typedef union {
74     firm_kind *kind;    /**< is either k_ir_node or k_ir_loop */
75     ir_node *node;      /**< Pointer to an ir_node element */
76     ir_loop *son;       /**< Pointer to an ir_loop element */
77 } loop_element;
78
79 int      is_ir_loop(const void *thing);
80
81 /** Set the outermost loop in ir graph as basic access to loop tree. */
82 void     set_irg_loop(ir_graph *irg, ir_loop *l);
83 ir_loop *get_irg_loop(ir_graph *irg);
84
85 /** Returns the loop n is contained in.  NULL if node is in no loop. */
86 ir_loop *get_irn_loop(ir_node *n);
87
88 /** Returns outer loop, itself if outermost. */
89 ir_loop *get_loop_outer_loop (ir_loop *loop);
90 /** Returns nesting depth of this loop */
91 int      get_loop_depth (ir_loop *loop);
92
93 /* Sons are the inner loops contained in this loop. */
94 /** Returns the number of inner loops */
95 int      get_loop_n_sons (ir_loop *loop);
96 ir_loop *get_loop_son (ir_loop *loop, int pos);
97 /** Returns the number of nodes contained in loop.  */
98 int      get_loop_n_nodes (ir_loop *loop);
99 ir_node *get_loop_node (ir_loop *loop, int pos);
100
101 /** Returns the number of elements contained in loop.  */
102 int      get_loop_n_elements (ir_loop *loop);
103 /** Returns a loop element.  A loop element can be interpreted as a
104     kind pointer, an ir_node* or an ir_loop*. */
105 loop_element get_loop_element (ir_loop *loop, int pos);
106
107 /** Returns the element number of the loop son in loop.
108  *  Returns -1 if not found. O(#elements). */
109 int get_loop_element_pos(ir_loop *loop, void *le);
110
111 /** Returns a unique node number for the loop node to make output
112     readable. If libfirm_debug is not set it returns the loop cast to
113     int. */
114 int get_loop_loop_nr(ir_loop *loop);
115
116 /** A field to connect additional information to a loop.  Only valid
117     if libfirm_debug is set, else returns NULL.  */
118 void  set_loop_link (ir_loop *loop, void *link);
119 void *get_loop_link (const ir_loop *loop);
120
121 /*
122  * Constructing and destructing the loop/backedge information.
123  */
124
125 /** Constructs backedge information for irg in intraprocedural view.
126  *  @returns Maximal depth of loop tree. */
127 /* @@@ Well, maybe construct_loop_information or analyze_loops ? */
128 int construct_backedges(ir_graph *irg);
129
130 /** Constructs backedges for all irgs in interprocedural view.  All
131     loops in the graph will be marked as such, not only realizeable
132     loops and recursions in the program.  E.g., if the same funcion is
133     called twice, there is a loop between the first function return and
134     the second call.
135  *  @returns Maximal depth of loop tree. */
136 int construct_ip_backedges(void);
137
138 /* Construct loop tree only for control flow.
139  * @returns Maximal depth of loop tree. */
140 int construct_cf_backedges(ir_graph *irg);
141 int construct_ip_cf_backedges (void);
142
143 /** Removes all loop information.
144     Resets all backedges */
145 void free_loop_information(ir_graph *irg);
146 void free_all_loop_information (void);
147
148 #endif /* _IRLOOP_H_ */