more
[libfirm] / ir / ir / iredges_t.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/iredges_t.h
4  * Purpose:     Everlasting outs -- private header.
5  * Author:      Sebastian Hack
6  * Created:     15.01.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  * everlasting outs.
14  * @author Sebastian Hack
15  * @date 15.1.2005
16  */
17
18 #ifndef _FIRM_EDGES_T_H
19 #define _FIRM_EDGES_T_H
20
21 #include "config.h"
22 #include "debug.h"
23
24 #include "set.h"
25 #include "list.h"
26
27 #include "irnode_t.h"
28 #include "irgraph_t.h"
29
30 #include "iredges.h"
31
32 #if FIRM_EDGES_INPLACE
33
34 #define DBG_EDGES  "edges"
35
36 /**
37  * An edge.
38  */
39 typedef struct _ir_edge_t {
40 #ifdef DEBUG_libfirm
41   long src_nr;            /**< The node number of the source node. */
42 #endif
43   ir_node *src;           /**< The source node of the edge. */
44   int pos;                /**< The position of the edge at @p src. */
45   struct list_head list;  /**< The list head to queue all out edges at a node. */
46   unsigned invalid : 1;   /**< edges that are removed are marked invalid. */
47   unsigned present : 1;   /**< Used by the verifier. Don't rely on its content. */
48 } ir_edge_t;
49
50 /** Accessor for private irn info. */
51 #define _get_irn_edge_info(irn) ((irn_edge_info_t *) &(irn)->edge_info)
52
53 /** Accessor for private irg info. */
54 #define _get_irg_edge_info(irg) ((irg_edge_info_t *) &(irg)->edge_info)
55
56 /**
57  * Convenience macro to get the outs_head from a irn_edge_info_t
58  * struct.
59  */
60 #define _get_irn_outs_head(irn) (&_get_irn_edge_info(irn)->outs_head)
61
62 /**
63  * Get the first edge pointing to some node.
64  * @note There is no order on out edges. First in this context only
65  * means, that you get some starting point into the list of edges.
66  * @param irn The node.
67  * @return The first out edge that points to this node.
68  */
69 static INLINE const ir_edge_t *_get_irn_out_edge_first(const ir_node *irn)
70 {
71   struct list_head *head = _get_irn_outs_head(irn);
72   return list_empty(head) ? NULL : list_entry(head->next, ir_edge_t, list);
73 }
74
75 /**
76  * Get the next edge in the out list of some node.
77  * @param irn The node.
78  * @param last The last out edge you have seen.
79  * @return The next out edge in @p irn 's out list after @p last.
80  */
81 static INLINE const ir_edge_t *_get_irn_out_edge_next(const ir_node *irn, const ir_edge_t *last)
82 {
83   struct list_head *next = last->list.next;
84   return next == _get_irn_outs_head(irn) ? NULL : list_entry(next, ir_edge_t, list);
85 }
86
87 /**
88  * A convenience iteration macro over all out edges of a node.
89  * @param irn The node.
90  * @param edge An @c ir_edge_t pointer which shall be set to the current
91  * edge.
92  */
93 #define foreach_out_edge(irn,edge) \
94   for(edge = get_irn_out_edge_first(irn); edge; edge = get_irn_out_edge_next(irn, edge))
95
96 /**
97  * Get the source node of an edge.
98  * @param edge The edge.
99  * @return The source node of that edge.
100  */
101 static INLINE  ir_node *_get_edge_src_irn(const ir_edge_t *edge)
102 {
103   return edge ? edge->src : NULL;
104 }
105
106 /**
107  * Get the position of an edge.
108  * @param edge.
109  * @return The position in the in array of that edges source.
110  */
111 static INLINE int _get_edge_src_pos(const ir_edge_t *edge)
112 {
113   return edge ? edge->pos : -1;
114 }
115
116 static INLINE int _edges_activated(const ir_graph *irg)
117 {
118   return _get_irg_edge_info(irg)->activated;
119 }
120
121 void edges_reroute(ir_node *old, ir_node *nw, ir_graph *irg);
122
123 void edges_init_graph(ir_graph *irg);
124
125 void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir_graph *irg);
126
127 void edges_node_deleted(ir_node *old, ir_graph *irg);
128
129 void edges_invalidate(ir_node *irn, ir_graph *irg);
130
131 /**
132  * Initialize the out edges.
133  * This must be called before firm is initialized.
134  */
135 extern void init_edges(void);
136
137 #define get_irn_out_edge_first(irn)      _get_irn_out_edge_first(irn)
138 #define get_irn_out_edge_next(irn,last)  _get_irn_out_edge_next(irn, last)
139 #define get_edge_src_irn(edge)           _get_edge_src_irn(edge)
140 #define get_edge_src_pos(edge)           _get_edge_src_pos(edge)
141 #define edges_activated(irg)             _edges_activated(irg)
142
143 #else
144 /* new edges are disabled */
145
146 #define init_edges()
147 #define edges_reroute(old, nw, irg)
148 #define edges_init_graph(irg);
149 #define edges_notify_edge(src, pos, tgt, old_tgt, irg)
150 #define edges_node_deleted(old, irg)
151 #define edges_invalidate(irn, irg)
152 #define get_irn_out_edge_first(irn)       NULL
153 #define get_irn_out_edge_next(irn,last)   NULL
154 #define get_edge_src_irn(edge)            NULL
155 #define get_edge_src_pos(edge)            -1
156 #define edges_activated(irg)              0
157
158 #endif /* FIRM_EDGES_INPLACE */
159
160 #endif /* _FIRM_EDGES_T_H */