3 * File name: ir/ana/irloop_t.h
4 * Purpose: Loop datastructure and access functions.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 2002-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
16 * Computes backedges in the control and data flow.
18 * @author Goetz Lindenmaier
20 * Only Block and Phi/Filter nodes can have incoming backedges.
21 * Constructs loops data structure: indicates loop nesting.
31 /* @@@ Interprocedural backedges ... ???? */
34 * Backedge information.
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.
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);
55 * The loops datastructure.
57 * The loops datastructure represents circles in the intermediate
58 * representation. It does not represent loops in the terms of a
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
67 * @todo We could add a field pointing from a node to the containing loop,
68 * this would cost a lot of memory, though.
70 typedef struct ir_loop ir_loop;
72 /* Loop elements are loop nodes and ir nodes */
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 */
79 void set_irg_loop(ir_graph *irg, ir_loop *l);
80 ir_loop *get_irg_loop(ir_graph *irg);
82 /** Returns the loop n is contained in. NULL if node is in no loop. */
83 ir_loop *get_irn_loop(ir_node *n);
85 /** Returns outer loop, itself if outermost. */
86 ir_loop *get_loop_outer_loop (ir_loop *loop);
87 /** Returns nesting depth of this loop */
88 int get_loop_depth (ir_loop *loop);
90 /* Sons are the inner loops contained in this loop. */
91 /** Returns the number of inner loops */
92 int get_loop_n_sons (ir_loop *loop);
93 ir_loop *get_loop_son (ir_loop *loop, int pos);
94 /** Returns the number of nodes contained in loop. */
95 int get_loop_n_nodes (ir_loop *loop);
96 ir_node *get_loop_node (ir_loop *loop, int pos);
98 /** Returns the number of elements contained in loop. */
99 int get_loop_n_elements (ir_loop *loop);
100 /** Returns a loop element. A loop element can be interpreted as a
101 kind pointer, an ir_node* or an ir_loop*. */
102 loop_element get_loop_element (ir_loop *loop, int pos);
104 /** Returns the element number of the loop son in loop.
105 * Returns -1 if not found. O(#elements). */
106 int get_loop_element_pos(ir_loop *loop, void *le);
108 /** Returns a unique node number for the loop node to make output
110 int get_loop_loop_nr(ir_loop *loop);
114 * Constructing and destructing the loop/backedge information.
117 /** Constructs backedge information for irg in intraprocedural view. */
118 /* @@@ Well, maybe construct_loop_information or analyze_loops ? */
119 void construct_backedges(ir_graph *irg);
121 /** Constructs backedges for all irgs in interprocedural view. All
122 loops in the graph will be marked as such, not only realizeable
123 loops and recursions in the program. E.g., if the same funcion is
124 called twice, there is a loop between the first function return and
126 void construct_ip_backedges(void);
128 /** Removes all loop information.
129 Resets all backedges */
130 void free_loop_information(ir_graph *irg);
131 void free_all_loop_information (void);
133 #endif /* _IRLOOP_H_ */