2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Random node selector.
9 * @author Matthias Braun
17 #include "belistsched.h"
21 * The random selector:
22 * Just assure that branches are executed last, otherwise select a random node
24 static ir_node *random_select(void *block_env, ir_nodeset_t *ready_set)
26 int only_branches_left = 1;
29 /* assure that branches and constants are executed last */
30 foreach_ir_nodeset(ready_set, irn, iter) {
32 only_branches_left = 0;
37 ir_node *rand_node = NULL;
38 if (only_branches_left) {
39 /* at last: schedule branches */
40 rand_node = ir_nodeset_first(ready_set);
43 /* take 1 random node */
44 int n = rand() % ir_nodeset_size(ready_set);
46 foreach_ir_nodeset(ready_set, irn, iter) {
53 } while (is_cfop(rand_node));
59 static void *random_init_graph(ir_graph *irg)
62 /* TODO: add commandline option for the seed */
67 static void *random_init_block(void *graph_env, ir_node *block)
74 static void sched_random(ir_graph *irg)
76 static const list_sched_selector_t random_selector = {
80 NULL, /* node_ready */
81 NULL, /* node_selected */
82 NULL, /* finish_block */
83 NULL /* finish_graph */
85 be_list_sched_graph(irg, &random_selector);
88 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_sched_rand)
89 void be_init_sched_rand(void)
91 be_register_scheduler("random", sched_random);