do C99 compliance
[libfirm] / ir / be / besched_t.h
1
2 #ifndef _BESCHED_T_H
3 #define _BESCHED_T_H
4
5 #include "list.h"
6 #include "irnode_t.h"
7 #include "irgraph_t.h"
8
9 extern size_t sched_irn_data_offset;
10
11 typedef struct _sched_info_t {
12         struct list_head list;
13         int time_step;
14
15         unsigned is_last_use_in_block : 1;
16 } sched_info_t;
17
18 #define _sched_entry(list_head) (list_entry(list_head, sched_info_t, list))
19
20 #define get_irn_sched_info(irn) get_irn_data(irn, sched_info_t, sched_irn_data_offset)
21 #define get_sched_info_irn(sched_info) get_irn_data_base(sched_info, sched_irn_data_offset)
22
23 /**
24  * Check, if an ir_node has a scheduling successor.
25  * @param irn The ir node.
26  * @return 1, if the node has a scheduling successor, 0 if not.
27  */
28 static INLINE int sched_has_succ(const ir_node *irn)
29 {
30         const sched_info_t *info = get_irn_sched_info(irn);
31         const sched_info_t *block_info = get_irn_sched_info(get_nodes_block(irn));
32         return info->list.next != &block_info->list;
33 }
34
35 /**
36  * Check, if an ir_node has a scheduling predecessor.
37  * @param irn The ir node.
38  * @return 1, if the node has a scheduling predecessor, 0 if not.
39  */
40 static INLINE int sched_has_prev(const ir_node *irn)
41 {
42         const sched_info_t *info = get_irn_sched_info(irn);
43         const sched_info_t *block_info = get_irn_sched_info(get_nodes_block(irn));
44         return info->list.prev != &block_info->list;
45 }
46
47 /**
48  * Get the scheduling successor of a node.
49  * @param irn The node.
50  * @return The next ir node in the schedule or NULL, if this node has no
51  * successor.
52  */
53 static INLINE const ir_node *sched_succ(const ir_node *irn)
54 {
55         const sched_info_t *info = get_irn_sched_info(irn);
56         return sched_has_succ(irn) ? get_sched_info_irn(_sched_entry(info->list.next)) : NULL;
57 }
58
59 /**
60  * Get the scheduling predecessor of a node.
61  * @param irn The node.
62  * @return The next ir node in the schedule or NULL, if this node has no
63  * predecessor.
64  */
65 static INLINE const ir_node *sched_prev(const ir_node *irn)
66 {
67         const sched_info_t *info = get_irn_sched_info(irn);
68         return sched_has_prev(irn) ? get_sched_info_irn(_sched_entry(info->list.prev)) : NULL;
69 }
70
71 /**
72  * Get the first node in a block schedule.
73  * @param block The block of which to get the schedule.
74  * @return The first node in the schedule or NULL if there is none.
75  */
76 static INLINE const ir_node *sched_first(const ir_node *block)
77 {
78         const sched_info_t *info = get_irn_sched_info(block);
79         assert(is_Block(block) && "Need a block here");
80         return !list_empty(&info->list) ? get_sched_info_irn(_sched_entry(info->list.next)) : NULL;
81 }
82
83 /**
84  * Get the last node in a schedule.
85  * @param block The block to get the schedule for.
86  * @return The last ir node in a schedule, or NULL if no schedule exists
87  * or it is empty.
88  */
89 static INLINE const ir_node *sched_last(const ir_node *block)
90 {
91         const sched_info_t *info = get_irn_sched_info(block);
92         assert(is_Block(block) && "Need a block here");
93         return !list_empty(&info->list) ? get_sched_info_irn(_sched_entry(info->list.prev)) : NULL;
94 }
95
96 /**
97  * Add a node to a block schedule.
98  * @param block The block to whose schedule the node shall be added to.
99  * @param irn The node to add.
100  * @return The given node.
101  */
102 static INLINE const ir_node *sched_add(ir_node *block, const ir_node *irn)
103 {
104         assert(is_Block(block) && "Need a block here");
105         list_add_tail(&get_irn_sched_info(irn)->list, &get_irn_sched_info(block)->list);
106         return irn;
107 }
108
109 /**
110  * A shorthand macro for iterating over a schedule.
111  * @param block The block.
112  * @param irn A ir node pointer used as an iterator.
113  */
114 #define sched_foreach(block,irn) for(irn = sched_first(block); irn; irn = sched_succ(irn))
115
116
117 #define sched_foreach_reverse(block,irn) \
118         for(irn = sched_last(block); irn; irn = sched_prev(irn))
119
120 #endif