rework schedulers to register similar like regallocators/spillers
[libfirm] / ir / be / belistsched.h
1 /*
2  * Copyright (C) 1995-2008 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       Common functions for creating listscheduling algorithms
23  * @author      Sebastian Hack
24  * @date        20.10.2004
25  * @version     $Id$
26  */
27 #ifndef FIRM_BE_BELISTSCHED_H
28 #define FIRM_BE_BELISTSCHED_H
29
30 #include "firm_types.h"
31 #include "irnodeset.h"
32
33 #include "be.h"
34 #include "be_types.h"
35 #include "bearch.h"
36 #include "beirg.h"
37
38 /**
39  * Checks, if a node is to appear in a schedule. Such nodes either
40  * consume real data (mode datab) or produce such.
41  * @param irn The node to check for.
42  * @return 1, if the node consumes/produces data, false if not.
43  */
44 static inline bool to_appear_in_schedule(const ir_node *irn)
45 {
46         switch(get_irn_opcode(irn)) {
47         case iro_Anchor:
48         case iro_Bad:
49         case iro_Block:
50         case iro_Confirm:
51         case iro_Dummy:
52         case iro_End:
53         case iro_NoMem:
54         case iro_Pin:
55         case iro_Proj:
56         case iro_Sync:
57         case iro_Unknown:
58                 return false;
59         case iro_Phi:
60                 return mode_is_data(get_irn_mode(irn));
61         default:
62                 return ! (arch_irn_get_flags(irn) & arch_irn_flags_not_scheduled);
63         }
64 }
65
66 /**
67  * A selector interface which is used by the list schedule framework.
68  * You can implement your own list scheduler by implementing these
69  * functions.
70  */
71 typedef struct list_sched_selector_t {
72
73         /**
74          * Called before a graph is being scheduled.
75          * May be NULL.
76          *
77          * @param vtab     The selector vtab.
78          * @param irg      The backend graph.
79          * @return         The environment pointer that is passed to all other functions in this struct.
80          */
81         void *(*init_graph)(ir_graph *irg);
82
83         /**
84          * Called before scheduling starts on a block.
85          * May be NULL.
86          *
87          * @param graph_env   The environment.
88          * @param block       The block which is to be scheduled.
89          * @return A per-block pointer that is additionally passed to select.
90          */
91         void *(*init_block)(void *graph_env, ir_node *block);
92
93         /**
94          * The selection function.
95          * It picks one node out of the ready list to be scheduled next.
96          * The function does not have to delete the node from the ready set.
97          * MUST be implemented.
98          *
99          * @param block_env   Some private information as returned by init_block().
100          * @param sched_head  The schedule so far.
101          * @param ready_set   A set containing all ready nodes. Pick one of these nodes.
102          * @param live_set    A set containing all nodes currently alive.
103          * @return The chosen node.
104          */
105         ir_node *(*select)(void *block_env, ir_nodeset_t *ready_set,
106                        ir_nodeset_t *live_set);
107
108         /**
109          * This function gets executed after a node finally has been made ready.
110          * May be NULL.
111          *
112          * @param block_env The block environment.
113          * @param irn       The node made ready.
114          * @param pred      The previously scheduled node.
115          */
116         void (*node_ready)(void *block_env, ir_node *irn, ir_node *pred);
117
118         /**
119          * This function gets executed after a node finally has been selected.
120          * May be NULL.
121          *
122          * @param block_env The block environment.
123          * @param irn       The selected node.
124          */
125         void (*node_selected)(void *block_env, ir_node *irn);
126
127         /**
128          * Called after a block has been scheduled.
129          * May be NULL.
130          *
131          * @param env The environment.
132          * @param block_env The per block environment as returned by init_block().
133          */
134         void (*finish_block)(void *block_env);
135
136         /**
137          * Called after a whole graph has been scheduled.
138          * May be NULL.
139          *
140          * @param env The environment.
141          */
142         void (*finish_graph)(void *env);
143 } list_sched_selector_t;
144
145 /**
146  * List schedule a graph.
147  * Each block in the graph gets a list head to its link field being the
148  * head of the schedule. You can walk this list using the functions in
149  * list.h.
150  *
151  * @param irg     The backend irg.
152  */
153 void be_list_sched_graph(ir_graph *irg, const list_sched_selector_t *selector);
154
155 #endif