2 * Trivial node selector.
3 * @author Matthias Braun
13 #include "besched_t.h"
14 #include "belistsched.h"
17 * The random selector:
18 * Just assure that branches are executed last, otherwise select a random node
20 static ir_node *random_select(void *block_env, nodeset *ready_set, nodeset *live_set)
22 const arch_env_t *arch_env = block_env;
24 int only_branches_left = 1;
26 /* assure that branches and constants are executed last */
27 for (irn = nodeset_first(ready_set); irn; irn = nodeset_next(ready_set)) {
28 if (! arch_irn_class_is(arch_env, irn, branch)) {
29 only_branches_left = 0;
30 nodeset_break(ready_set);
35 if(only_branches_left) {
36 /* at last: schedule branches */
37 irn = nodeset_first(ready_set);
38 nodeset_break(ready_set);
42 int n = rand() % pset_count(ready_set);
44 for(irn = nodeset_first(ready_set); irn; irn = nodeset_next(ready_set)) {
46 nodeset_break(ready_set);
51 } while(arch_irn_class_is(arch_env, irn, branch));
57 static void *random_init_graph(const list_sched_selector_t *vtab, const arch_env_t *arch_env, ir_graph *irg)
59 /* Using time(NULL) as a seed here gives really random results,
60 but is NOT deterministic which makes debugging impossible.
61 Moreover no-one want non-deterministic compilers ... */
63 return (void *)arch_env;
66 static void *random_init_block(void *graph_env, ir_node *bl)
71 static const list_sched_selector_t random_selector_struct = {
75 NULL, /* to_appear_in_schedule */
76 NULL, /* node_ready */
77 NULL, /* node_selected */
80 NULL, /* finish_block */
81 NULL /* finish_graph */
84 const list_sched_selector_t *random_selector = &random_selector_struct;