Changed __ to _
[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 #include "besched.h"
10
11 extern size_t sched_irn_data_offset;
12
13 typedef struct _sched_info_t {
14         struct list_head list;
15         int time_step;
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  * Init the scheduling stuff.
25  * To be called from the central backend initialization routine.
26  */
27 void be_sched_init(void);
28
29 /**
30  * Get the time step of an irn in a schedule.
31  * @param irn The node.
32  * @return The time step in the schedule.
33  */
34 static INLINE int _sched_get_time_step(const ir_node *irn)
35 {
36         return get_irn_sched_info(irn)->time_step;
37 }
38
39 /**
40  * Check, if an ir_node has a scheduling successor.
41  * @param irn The ir node.
42  * @return 1, if the node has a scheduling successor, 0 if not.
43  */
44 static INLINE int _sched_has_succ(const ir_node *irn)
45 {
46         const sched_info_t *info = get_irn_sched_info(irn);
47         const sched_info_t *block_info = get_irn_sched_info(get_nodes_block(irn));
48         return info->list.next != &block_info->list;
49 }
50
51 /**
52  * Check, if an ir_node has a scheduling predecessor.
53  * @param irn The ir node.
54  * @return 1, if the node has a scheduling predecessor, 0 if not.
55  */
56 static INLINE int _sched_has_prev(const ir_node *irn)
57 {
58         const sched_info_t *info = get_irn_sched_info(irn);
59         const sched_info_t *block_info = get_irn_sched_info(get_nodes_block(irn));
60         return info->list.prev != &block_info->list;
61 }
62
63 /**
64  * Get the scheduling successor of a node.
65  * @param irn The node.
66  * @return The next ir node in the schedule or NULL, if this node has no
67  * successor.
68  */
69 static INLINE ir_node *_sched_succ(const ir_node *irn)
70 {
71         const sched_info_t *info = get_irn_sched_info(irn);
72         return _sched_has_succ(irn) ? get_sched_info_irn(_sched_entry(info->list.next)) : NULL;
73 }
74
75 /**
76  * Get the scheduling predecessor of a node.
77  * @param irn The node.
78  * @return The next ir node in the schedule or NULL, if this node has no
79  * predecessor.
80  */
81 static INLINE ir_node *_sched_prev(const ir_node *irn)
82 {
83         const sched_info_t *info = get_irn_sched_info(irn);
84         return _sched_has_prev(irn) ? get_sched_info_irn(_sched_entry(info->list.prev)) : NULL;
85 }
86
87 /**
88  * Get the first node in a block schedule.
89  * @param block The block of which to get the schedule.
90  * @return The first node in the schedule or NULL if there is none.
91  */
92 static INLINE ir_node *_sched_first(const ir_node *block)
93 {
94         const sched_info_t *info = get_irn_sched_info(block);
95         assert(is_Block(block) && "Need a block here");
96         return !list_empty(&info->list) ? get_sched_info_irn(_sched_entry(info->list.next)) : NULL;
97 }
98
99 /**
100  * Get the last node in a schedule.
101  * @param block The block to get the schedule for.
102  * @return The last ir node in a schedule, or NULL if no schedule exists
103  * or it is empty.
104  */
105 static INLINE ir_node *_sched_last(const ir_node *block)
106 {
107         const sched_info_t *info = get_irn_sched_info(block);
108         assert(is_Block(block) && "Need a block here");
109         return !list_empty(&info->list) ? get_sched_info_irn(_sched_entry(info->list.prev)) : NULL;
110 }
111
112 /**
113  * Add a node to a block schedule.
114  * @param block The block to whose schedule the node shall be added to.
115  * @param irn The node to add.
116  * @return The given node.
117  */
118 static INLINE ir_node *_sched_add(ir_node *block, ir_node *irn)
119 {
120         assert(is_Block(block) && "Need a block here");
121         list_add_tail(&get_irn_sched_info(irn)->list, &get_irn_sched_info(block)->list);
122         return irn;
123 }
124
125 #define sched_get_time_step(irn)          _sched_get_time_step(irn)
126 #define sched_has_succ(irn)                             _sched_has_succ(irn)
127 #define sched_has_prev(irn)                             _sched_has_prev(irn)
128 #define sched_succ(irn)                                                 _sched_succ(irn)
129 #define sched_prev(irn)                                                 _sched_prev(irn)
130 #define sched_first(irn)                                                _sched_first(irn)
131 #define sched_last(irn)                                                 _sched_last(irn)
132 #define sched_add(block,irn)                            _sched_add(block,irn)
133
134
135 #endif