Fixed some typos.
[libfirm] / ir / ir / iredges_t.h
1 /*
2  * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Everlasting outs -- private header.
23  * @author  Sebastian Hack, Andreas Schoesser
24  * @date    15.01.2005
25  */
26 #ifndef FIRM_IR_EDGES_T_H
27 #define FIRM_IR_EDGES_T_H
28
29 #include "debug.h"
30
31 #include "set.h"
32 #include "list.h"
33
34 #include "irnode_t.h"
35 #include "irgraph_t.h"
36
37 #include "iredgekinds.h"
38 #include "iredges.h"
39
40 #define get_irn_n_edges_kind(irn, kind)   get_irn_n_edges_kind_(irn, kind)
41 #define get_edge_src_irn(edge)            get_edge_src_irn_(edge)
42 #define get_edge_src_pos(edge)            get_edge_src_pos_(edge)
43 #define get_irn_out_edge_next(irn, last, kind)  get_irn_out_edge_next_(irn, last, kind)
44 #define get_irn_n_edges(irn)              get_irn_n_edges_kind_(irn, EDGE_KIND_NORMAL)
45 #define get_irn_out_edge_first(irn)       get_irn_out_edge_first_kind_(irn, EDGE_KIND_NORMAL)
46 #define get_block_succ_first(irn)         get_irn_out_edge_first_kind_(irn, EDGE_KIND_BLOCK)
47 #define get_block_succ_next(irn, last)    get_irn_out_edge_next_(irn, last, EDGE_KIND_BLOCK)
48
49 /**
50  * An edge.
51  */
52 struct ir_edge_t {
53         ir_node  *src;          /**< The source node of the edge. */
54         int      pos;           /**< The position of the edge at @p src. */
55 #ifdef DEBUG_libfirm
56         unsigned present : 1;   /**< Used by the verifier. Don't rely on its content. */
57 #endif
58         struct list_head list;  /**< The list head to queue all out edges at a node. */
59 };
60
61 /** Accessor for private irn info. */
62 static inline irn_edge_info_t *get_irn_edge_info(ir_node *node,
63                                                  ir_edge_kind_t kind)
64 {
65         return &node->edge_info[kind];
66 }
67
68 static inline const irn_edge_info_t *get_irn_edge_info_const(
69                 const ir_node *node, ir_edge_kind_t kind)
70 {
71         return &node->edge_info[kind];
72 }
73
74 /** Accessor for private irg info. */
75 static inline irg_edge_info_t *get_irg_edge_info(ir_graph *irg,
76                                                  ir_edge_kind_t kind)
77 {
78         return &irg->edge_info[kind];
79 }
80
81 /** Accessor for private irg info. */
82 static inline const irg_edge_info_t *get_irg_edge_info_const(
83                 const ir_graph *irg, ir_edge_kind_t kind)
84 {
85         return &irg->edge_info[kind];
86 }
87
88 /**
89  * Get the first edge pointing to some node.
90  * @note There is no order on out edges. First in this context only
91  * means, that you get some starting point into the list of edges.
92  * @param irn The node.
93  * @return The first out edge that points to this node.
94  */
95 static inline const ir_edge_t *get_irn_out_edge_first_kind_(const ir_node *irn, ir_edge_kind_t kind)
96 {
97         const struct list_head *head;
98         assert(edges_activated_kind(get_irn_irg(irn), kind));
99         head = &get_irn_edge_info_const(irn, kind)->outs_head;
100         return list_empty(head) ? NULL : list_entry(head->next, ir_edge_t, list);
101 }
102
103 /**
104  * Get the next edge in the out list of some node.
105  * @param irn The node.
106  * @param last The last out edge you have seen.
107  * @return The next out edge in @p irn 's out list after @p last.
108  */
109 static inline const ir_edge_t *get_irn_out_edge_next_(const ir_node *irn, const ir_edge_t *last, ir_edge_kind_t kind)
110 {
111         struct list_head *next = last->list.next;
112         const struct list_head *head
113                 = &get_irn_edge_info_const(irn, kind)->outs_head;
114         return next == head ? NULL : list_entry(next, ir_edge_t, list);
115 }
116
117 /**
118  * Get the number of edges pointing to a node.
119  * @param irn The node.
120  * @return The number of edges pointing to this node.
121  */
122 static inline int get_irn_n_edges_kind_(const ir_node *irn, ir_edge_kind_t kind)
123 {
124         return get_irn_edge_info_const(irn, kind)->out_count;
125 }
126
127 static inline int edges_activated_kind_(const ir_graph *irg, ir_edge_kind_t kind)
128 {
129         return get_irg_edge_info_const(irg, kind)->activated;
130 }
131
132 static inline int edges_activated_(const ir_graph *irg)
133 {
134         return edges_activated_kind(irg, EDGE_KIND_NORMAL)
135             && edges_activated_kind(irg, EDGE_KIND_BLOCK);
136 }
137
138 /**
139  * Assure, that the edges information is present for a certain graph.
140  * @param irg The graph.
141  */
142 static inline void edges_assure_kind_(ir_graph *irg, ir_edge_kind_t kind)
143 {
144         if(!edges_activated_kind_(irg, kind))
145                 edges_activate_kind(irg, kind);
146 }
147
148 void edges_init_graph_kind(ir_graph *irg, ir_edge_kind_t kind);
149
150 void edges_node_deleted(ir_node *irn);
151
152 /**
153  * A node might be revivaled by CSE.
154  */
155 void edges_node_revival(ir_node *node);
156
157 void edges_invalidate_kind(ir_node *irn, ir_edge_kind_t kind);
158
159 static inline ir_node *get_edge_src_irn_(const ir_edge_t *edge)
160 {
161         return edge->src;
162 }
163
164 static inline int get_edge_src_pos_(const ir_edge_t *edge)
165 {
166         return edge->pos;
167 }
168
169 /**
170  * Returns the edge object of an outgoing edge at a node.
171  * @param  irn  The node at which the edge originates.
172  * @param  pos  The position of the edge.
173  * @param  kind The kind of the edge.
174  * @return      The corresponding edge object or NULL,
175  *              if no such edge exists.
176  */
177 FIRM_API const ir_edge_t *get_irn_edge_kind(const ir_node *irn,
178                                             int pos, ir_edge_kind_t kind);
179
180 /**
181  * Initialize the out edges.
182  * This must be called before firm is initialized.
183  */
184 extern void init_edges(void);
185
186 void edges_invalidate_all(ir_node *irn);
187
188 /**
189  * Helper function to dump the edge set of a graph,
190  * unused in normal code.
191  */
192 void edges_dump_kind(ir_graph *irg, ir_edge_kind_t kind);
193
194 void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt,
195                        ir_graph *irg);
196
197 #endif