2 * Copyright (C) 1995-2007 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
21 * Trivial node selector.
22 * @author Matthias Braun
32 #include "besched_t.h"
33 #include "belistsched.h"
36 * The random selector:
37 * Just assure that branches are executed last, otherwise select a random node
39 static ir_node *random_select(void *block_env, ir_nodeset_t *ready_set,
40 ir_nodeset_t *live_set)
42 ir_nodeset_iterator_t iter;
43 const arch_env_t *arch_env = block_env;
45 int only_branches_left = 1;
47 /* assure that branches and constants are executed last */
48 ir_nodeset_iterator_init(&iter, ready_set);
49 while( (irn = ir_nodeset_iterator_next(&iter)) != NULL) {
50 if (! arch_irn_class_is(arch_env, irn, branch)) {
51 only_branches_left = 0;
56 if(only_branches_left) {
57 /* at last: schedule branches */
58 ir_nodeset_iterator_init(&iter, ready_set);
59 irn = ir_nodeset_iterator_next(&iter);
63 int n = rand() % ir_nodeset_size(ready_set);
65 ir_nodeset_iterator_init(&iter, ready_set);
66 while( (irn = ir_nodeset_iterator_next(&iter)) != NULL) {
72 } while(arch_irn_class_is(arch_env, irn, branch));
78 static void *random_init_graph(const list_sched_selector_t *vtab, const arch_env_t *arch_env, ir_graph *irg)
80 /* Using time(NULL) as a seed here gives really random results,
81 but is NOT deterministic which makes debugging impossible.
82 Moreover no-one want non-deterministic compilers ... */
84 return (void *)arch_env;
87 static void *random_init_block(void *graph_env, ir_node *bl)
92 static const list_sched_selector_t random_selector_struct = {
96 NULL, /* to_appear_in_schedule */
97 NULL, /* node_ready */
98 NULL, /* node_selected */
101 NULL, /* finish_block */
102 NULL /* finish_graph */
105 const list_sched_selector_t *random_selector = &random_selector_struct;