c2e9d2eec4911af6c4e962411bc7b3ac482676fc
[libfirm] / ir / be / besched.h
1 /*
2  * Scheduling utilities for nodes in Blocks and Blocks.
3  *
4  * $Id$
5  */
6 #ifndef _BESCHED_H
7 #define _BESCHED_H
8
9 #include <stdio.h>
10
11 #include "firm_types.h"
12
13 #include "execfreq.h"
14
15 void be_sched_dump(FILE *f, ir_graph *irg);
16
17 int     sched_get_time_step(const ir_node *irn);
18 int     sched_has_next(const ir_node *irn);
19 int     sched_has_prev(const ir_node *irn);
20 ir_node *sched_next(const ir_node *irn);
21 ir_node *sched_prev(const ir_node *irn);
22 ir_node *sched_first(const ir_node *block);
23 ir_node *sched_last(const ir_node *block);
24 ir_node *sched_add_before(ir_node *before, ir_node *irn);
25 ir_node *sched_add_after(ir_node *before, ir_node *irn);
26 void    sched_remove(ir_node *irn);
27
28 /**
29  * Returns the first block of a graphs block schedule.
30  */
31 ir_node *sched_irg_first(const ir_graph *irg);
32
33 #define sched_is_end(irn) is_Block(irn)
34 #define sched_is_begin(irn) is_Block(irn)
35
36 #define sched_foreach_from(from, irn) \
37   for(irn = from; !sched_is_end(irn); irn = sched_next(irn))
38
39 #define sched_foreach_reverse_from(from, irn) \
40   for(irn = from; !sched_is_begin(irn); irn = sched_prev(irn))
41
42 /**
43  * A shorthand macro for iterating over a schedule.
44  * @param block The block.
45  * @param irn A ir node pointer used as an iterator.
46  */
47 #define sched_foreach(block,irn) \
48         sched_foreach_from(sched_first(block), irn)
49
50 /**
51  * A shorthand macro for reversely iterating over a schedule.
52  * @param block The block.
53  * @param irn A ir node pointer used as an iterator.
54  */
55 #define sched_foreach_reverse(block,irn) \
56   sched_foreach_reverse_from(sched_last(block), irn)
57
58 /**
59  * Calculates a block schedule. The schedule is returned as
60  * an array allocated on the irg's obstack.
61  *
62  * @param irg  the graph to be scheduled
63  *
64  * @return A list of all blocks in schedule order. This list is
65  *         allocated on irg's obstack and is freed if the graph is destroyed.
66  *
67  * This function implements a simple extended block scheduling algorithm.
68  */
69 ir_node **sched_create_block_schedule(ir_graph *irg, ir_exec_freq *execfreqs);
70
71 /**
72  * Removes dead nodes from schedule
73  * @param irg  the graph
74  */
75 void be_remove_dead_nodes_from_schedule(ir_graph *irg);
76
77 #endif /* _BESCHED_H */