2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Random node selector.
23 * @author Matthias Braun
31 #include "belistsched.h"
35 * The random selector:
36 * Just assure that branches are executed last, otherwise select a random node
38 static ir_node *random_select(void *block_env, ir_nodeset_t *ready_set)
40 int only_branches_left = 1;
43 /* assure that branches and constants are executed last */
44 foreach_ir_nodeset(ready_set, irn, iter) {
46 only_branches_left = 0;
52 if (only_branches_left) {
53 /* at last: schedule branches */
54 irn = ir_nodeset_first(ready_set);
57 /* take 1 random node */
58 int n = rand() % ir_nodeset_size(ready_set);
60 foreach_ir_nodeset(ready_set, irn, iter) {
66 } while (is_cfop(irn));
72 static void *random_init_graph(ir_graph *irg)
75 /* TODO: add commandline option for the seed */
80 static void *random_init_block(void *graph_env, ir_node *block)
87 static void sched_random(ir_graph *irg)
89 static const list_sched_selector_t random_selector = {
93 NULL, /* node_ready */
94 NULL, /* node_selected */
95 NULL, /* finish_block */
96 NULL /* finish_graph */
98 be_list_sched_graph(irg, &random_selector);
101 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_sched_rand)
102 void be_init_sched_rand(void)
104 be_register_scheduler("random", sched_random);