bescripts: Remove unused execution unit specification.
[libfirm] / ir / be / besched.h
1 /*
2  * Copyright (C) 1995-2010 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       data structures for scheduling nodes in basic blocks.
23  * @author      Sebastian Hack, Matthias Braun
24  */
25 #ifndef FIRM_BE_BESCHED_H
26 #define FIRM_BE_BESCHED_H
27
28 #include <stdbool.h>
29
30 #include "beinfo.h"
31
32 static sched_info_t *get_irn_sched_info(const ir_node *node)
33 {
34         return &be_get_info(skip_Proj_const(node))->sched_info;
35 }
36
37 /**
38  * Check, if the node is scheduled.
39  * Block nodes are reported as scheduled as they mark the begin and end
40  * of the scheduling list.
41  * @param irn The node.
42  * @return 1, if the node is scheduled, 0 if not.
43  */
44 static inline bool sched_is_scheduled(const ir_node *irn)
45 {
46         return get_irn_sched_info(irn)->next != NULL;
47 }
48
49 /**
50  * Returns the time step of a node. Each node in a block has a timestep
51  * unique to that block. A node schedule before another node has a lower
52  * timestep than this node.
53  * @param irn The node.
54  * @return The time step in the schedule.
55  */
56 static inline sched_timestep_t sched_get_time_step(const ir_node *irn)
57 {
58         assert(sched_is_scheduled(irn));
59         return get_irn_sched_info(irn)->time_step;
60 }
61
62 static inline bool sched_is_end(const ir_node *node)
63 {
64         return is_Block(node);
65 }
66
67 static inline bool sched_is_begin(const ir_node *node)
68 {
69         return is_Block(node);
70 }
71
72 /**
73  * Get the scheduling successor of a node.
74  * @param irn The node.
75  * @return The next ir node in the schedule or the block, if the node has no next node.
76  */
77 static inline ir_node *sched_next(const ir_node *irn)
78 {
79         const sched_info_t *info = get_irn_sched_info(irn);
80         return info->next;
81 }
82
83 /**
84  * Get the scheduling predecessor of a node.
85  * @param irn The node.
86  * @return The next ir node in the schedule or the block, if the node has no predecessor.
87  * predecessor.
88  */
89 static inline ir_node *sched_prev(const ir_node *irn)
90 {
91         const sched_info_t *info = get_irn_sched_info(irn);
92         return info->prev;
93 }
94
95 /**
96  * Get the first node in a block schedule.
97  * @param block The block of which to get the schedule.
98  * @return The first node in the schedule or the block itself
99  *         if there is no node in the schedule.
100  */
101 static inline ir_node *sched_first(const ir_node *block)
102 {
103         assert(is_Block(block) && "Need a block here");
104         return sched_next(block);
105 }
106
107 /**
108  * Get the last node in a schedule.
109  * @param  block The block to get the schedule for.
110  * @return The last ir node in a schedule, or the block itself
111  *         if there is no node in the schedule.
112  */
113 static inline ir_node *sched_last(const ir_node *block)
114 {
115         assert(is_Block(block) && "Need a block here");
116         return sched_prev(block);
117 }
118
119 /**
120  * Add a node to a block schedule.
121  * @param irn The node to add.
122  * @return The given node.
123  */
124 void sched_add_before(ir_node *before, ir_node *irn);
125
126
127 /**
128  * Add a node to a block schedule.
129  * @param irn The node to add.
130  * @return The given node.
131  */
132 void sched_add_after(ir_node *after, ir_node *irn);
133
134 static inline void sched_init_block(ir_node *block)
135 {
136         sched_info_t *info = get_irn_sched_info(block);
137         assert(info->next == NULL && info->time_step == 0);
138         info->next = block;
139         info->prev = block;
140 }
141
142 static inline void sched_reset(ir_node *node)
143 {
144         sched_info_t *info = get_irn_sched_info(node);
145         info->next = NULL;
146         info->prev = NULL;
147 }
148
149 /**
150  * Remove a node from the scheduled.
151  * @param irn The node.
152  */
153 void sched_remove(ir_node *irn);
154
155 /**
156  * Checks, if one node is scheduled before another.
157  * @param n1   A node.
158  * @param n2   Another node.
159  * @return     true, if n1 is in front of n2 in the schedule, false else.
160  * @note       Both nodes must be in the same block.
161  */
162 static inline bool sched_comes_after(const ir_node *n1, const ir_node *n2)
163 {
164         assert((is_Block(n1) ? n1 : get_nodes_block(n1)) == (is_Block(n2) ? n2 : get_nodes_block(n2)));
165         return sched_get_time_step(n1) < sched_get_time_step(n2);
166 }
167
168 #define sched_foreach_from(from, irn) \
169   for (ir_node *irn = from; !sched_is_end(irn); irn = sched_next(irn))
170
171 #define sched_foreach_reverse_from(from, irn) \
172   for (ir_node *irn = from; !sched_is_begin(irn); irn = sched_prev(irn))
173
174 /**
175  * A shorthand macro for iterating over a schedule.
176  * @param block The block.
177  * @param irn A ir node pointer used as an iterator.
178  */
179 #define sched_foreach(block,irn) \
180         sched_foreach_from(sched_first(block), irn)
181
182 /**
183  * A shorthand macro for reversely iterating over a schedule.
184  * @param block The block.
185  * @param irn A ir node pointer used as an iterator.
186  */
187 #define sched_foreach_reverse(block,irn) \
188   sched_foreach_reverse_from(sched_last(block), irn)
189
190 /**
191  * Type for a function scheduling a graph
192  */
193 typedef void (*schedule_func) (ir_graph *irg);
194
195 /**
196  * Register new scheduling algorithm
197  */
198 void be_register_scheduler(const char *name, schedule_func func);
199
200 /**
201  * schedule a graph with the currenty selected scheduler.
202  */
203 void be_schedule_graph(ir_graph *irg);
204
205 #endif