header added
[libfirm] / ir / ir / iredges.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/iredges.h
4  * Purpose:     Public header for the automatically updating outs.
5  * Author:      Sebastian Hack
6  * Created:     3.2.2005
7  * CVS-ID:      $Id$
8  * Copyright:   (c) 1998-2005 Universität Karlsruhe
9  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
10  */
11
12 /**
13  * Public header for the automatically updating outs.
14  * @author Sebastian Hack
15  * @date 3.2.2005
16  */
17
18 #ifndef _FIRM_EDGES_H
19 #define _FIRM_EDGES_H
20
21 #include "irnode.h"
22
23 #ifndef _IR_EDGE_TYPEDEF_
24 #define _IR_EDGE_TYPEDEF_
25 typedef struct _ir_edge_t ir_edge_t;
26 #endif
27
28 #ifndef _IR_BLOCK_EDGE_TYPEDEF_
29 #define _IR_BLOCK_EDGE_TYPEDEF_
30 typedef struct _ir_block_edge_t ir_block_edge_t;
31 #endif
32
33 /**
34  * Get the first edge pointing to some node.
35  * @note There is no order on out edges. First in this context only
36  * means, that you get some starting point into the list of edges.
37  * @param irn The node.
38  * @return The first out edge that points to this node.
39  */
40 const ir_edge_t *get_irn_out_edge_first(const ir_node *irn);
41
42 /**
43  * Get the next edge in the out list of some node.
44  * @param irn The node.
45  * @param last The last out edge you have seen.
46  * @return The next out edge in @p irn 's out list after @p last.
47  */
48 const ir_edge_t *get_irn_out_edge_next(const ir_node *irn,
49                 const ir_edge_t *last);
50
51 /**
52  * A convenience iteration macro over all out edges of a node.
53  * @param irn  The node.
54  * @param edge An ir_edge_t pointer which shall be set to the current
55  * edge.
56  */
57 #define foreach_out_edge(irn,edge) \
58         for(edge = get_irn_out_edge_first(irn); edge; edge = get_irn_out_edge_next(irn, edge))
59
60 /**
61  * A convenience iteration macro over all out edges of a node, which is safe
62  * against alteration of the current edge.
63  *
64  * @param irn  The node.
65  * @param edge An ir_edge_t pointer which shall be set to the current
66  * edge.
67  * @param ne   The next edge, enables alteration safe edge processing.
68  */
69 #define foreach_out_edge_safe(irn,edge,ne) \
70         for( \
71                 (edge) = (get_irn_out_edge_first(irn)), \
72                         (ne) = ((edge) ? (get_irn_out_edge_next(irn, edge)) : NULL); \
73                 edge; \
74                 (edge) = (ne), (ne) = ((edge) ? (get_irn_out_edge_next(irn, edge)) : NULL) \
75         )
76
77
78 /**
79  * A convenience iteration macro for all control flow edges
80  * leaving a block, and thus are cf successor edges.
81  * @param bl The block.
82  * @param edge An @c ir_edge_t pointer which is set to the current edge.
83  */
84 #define foreach_block_succ(bl,edge) \
85         for(edge = get_block_succ_first(bl); edge; edge = get_block_succ_next(bl, edge))
86
87 /*
88  * Get the source node of an edge.
89  * @param edge The edge.
90  * @return The source node of that edge.
91  */
92 ir_node *get_edge_src_irn(const ir_edge_t *edge);
93
94 /**
95  * Get the number of edges pointing to a node.
96  * @param irn The node.
97  * @return The number of edges pointing to this node.
98  */
99 int get_irn_n_edges(const ir_node *irn);
100
101 /**
102  * Get the position of an edge.
103  * @param edge The edge.
104  * @return The position in the in array of that edges source.
105  */
106 extern int get_edge_src_pos(const ir_edge_t *edge);
107
108 /**
109  * Get the edge object of an outgoing edge at a node.
110  * @param   irg The graph, the node is in.
111  * @param   irn The node at which the edge originates.
112  * @param   pos The position of the edge.
113  * @return      The corresponding edge object or NULL,
114  *              if no such edge exists.
115  */
116 const ir_edge_t *get_irn_edge(ir_graph *irg, const ir_node *irn, int pos);
117
118 /**
119  * Check, if the out edges are activated.
120  * @param irg The graph.
121  * @return 1, if the edges are present for the given irg, 0 if not.
122  */
123 extern int edges_activated(const ir_graph *irg);
124
125 /**
126  * Activate the edges for an irg.
127  * @param irg The graph to activate the edges for.
128  **/
129 extern void edges_activate(ir_graph *irg);
130
131 /**
132  * Deactivate the edges for an irg.
133  * @param irg The graph.
134  */
135 extern void edges_deactivate(ir_graph *irg);
136
137 #endif /* _FIRM_EDGES_H */