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
22 * @brief Random node selector.
23 * @author Matthias Braun
33 #include "besched_t.h"
34 #include "belistsched.h"
37 * The random selector:
38 * Just assure that branches are executed last, otherwise select a random node
40 static ir_node *random_select(void *block_env, ir_nodeset_t *ready_set,
41 ir_nodeset_t *live_set)
43 ir_nodeset_iterator_t iter;
44 const arch_env_t *arch_env = block_env;
46 int only_branches_left = 1;
48 /* assure that branches and constants are executed last */
49 ir_nodeset_iterator_init(&iter, ready_set);
50 while( (irn = ir_nodeset_iterator_next(&iter)) != NULL) {
51 if (! arch_irn_class_is(arch_env, irn, branch)) {
52 only_branches_left = 0;
57 if (only_branches_left) {
58 /* at last: schedule branches */
59 ir_nodeset_iterator_init(&iter, ready_set);
60 irn = ir_nodeset_iterator_next(&iter);
63 /* take 1 random node */
64 int n = rand() % ir_nodeset_size(ready_set);
66 ir_nodeset_iterator_init(&iter, ready_set);
67 while ((irn = ir_nodeset_iterator_next(&iter)) != NULL) {
73 } while(arch_irn_class_is(arch_env, irn, branch));
79 static void *random_init_graph(const list_sched_selector_t *vtab, const arch_env_t *arch_env, ir_graph *irg)
81 /* Using time(NULL) as a seed here gives really random results,
82 but is NOT deterministic which makes debugging impossible.
83 Moreover no-one want non-deterministic compilers ... */
85 return (void *)arch_env;
88 static void *random_init_block(void *graph_env, ir_node *bl)
93 static const list_sched_selector_t random_selector_struct = {
97 NULL, /* to_appear_in_schedule */
98 NULL, /* node_ready */
99 NULL, /* node_selected */
102 NULL, /* finish_block */
103 NULL /* finish_graph */
106 const list_sched_selector_t *random_selector = &random_selector_struct;