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, ir_nodeset_t *ready_set,
21 ir_nodeset_t *live_set)
23 ir_nodeset_iterator_t iter;
24 const arch_env_t *arch_env = block_env;
26 int only_branches_left = 1;
28 /* assure that branches and constants are executed last */
29 ir_nodeset_iterator_init(&iter, ready_set);
30 while( (irn = ir_nodeset_iterator_next(&iter)) != NULL) {
31 if (! arch_irn_class_is(arch_env, irn, branch)) {
32 only_branches_left = 0;
37 if(only_branches_left) {
38 /* at last: schedule branches */
39 ir_nodeset_iterator_init(&iter, ready_set);
40 irn = ir_nodeset_iterator_next(&iter);
44 int n = rand() % ir_nodeset_size(ready_set);
46 ir_nodeset_iterator_init(&iter, ready_set);
47 while( (irn = ir_nodeset_iterator_next(&iter)) != NULL) {
53 } while(arch_irn_class_is(arch_env, irn, branch));
59 static void *random_init_graph(const list_sched_selector_t *vtab, const arch_env_t *arch_env, ir_graph *irg)
61 /* Using time(NULL) as a seed here gives really random results,
62 but is NOT deterministic which makes debugging impossible.
63 Moreover no-one want non-deterministic compilers ... */
65 return (void *)arch_env;
68 static void *random_init_block(void *graph_env, ir_node *bl)
73 static const list_sched_selector_t random_selector_struct = {
77 NULL, /* to_appear_in_schedule */
78 NULL, /* node_ready */
79 NULL, /* node_selected */
82 NULL, /* finish_block */
83 NULL /* finish_graph */
86 const list_sched_selector_t *random_selector = &random_selector_struct;