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
32 #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,
39 ir_nodeset_t *live_set)
41 ir_nodeset_iterator_t iter;
43 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) {
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);
62 /* take 1 random node */
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 (is_cfop(irn));
78 static void *random_init_graph(const list_sched_selector_t *vtab, ir_graph *irg)
82 /* Using time(NULL) as a seed here gives really random results,
83 but is NOT deterministic which makes debugging impossible.
84 Moreover no-one want non-deterministic compilers ... */
89 static void *random_init_block(void *graph_env, ir_node *block)
96 const list_sched_selector_t random_selector = {
100 NULL, /* node_ready */
101 NULL, /* node_selected */
104 NULL, /* finish_block */
105 NULL /* finish_graph */