X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbeschedrand.c;h=3388907a3f7033ba24b7096c92f28697c5df4cd6;hb=5cb14f12bacb0c7d1c646112b4660d57e14236a2;hp=8524abb2ca54150bf02e6b78c3c87fc8153f154f;hpb=c5e94f039082de17df10b34a3445c15c0af12f71;p=libfirm diff --git a/ir/be/beschedrand.c b/ir/be/beschedrand.c index 8524abb2c..3388907a3 100644 --- a/ir/be/beschedrand.c +++ b/ir/be/beschedrand.c @@ -1,9 +1,32 @@ +/* + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + /** - * Trivial node selector. - * @author Christian Wuerdig - * @date 29.08.2006 - * @cvs-id $Id$ + * @file + * @brief Random node selector. + * @author Matthias Braun + * @date 29.08.2006 + * @version $Id$ */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include @@ -14,33 +37,36 @@ * The random selector: * Just assure that branches are executed last, otherwise select a random node */ -static ir_node *random_select(void *block_env, nodeset *ready_set, nodeset *live_set) +static ir_node *random_select(void *block_env, ir_nodeset_t *ready_set, + ir_nodeset_t *live_set) { + ir_nodeset_iterator_t iter; const arch_env_t *arch_env = block_env; ir_node *irn = NULL; int only_branches_left = 1; + (void) live_set; /* assure that branches and constants are executed last */ - for (irn = nodeset_first(ready_set); irn; irn = nodeset_next(ready_set)) { + ir_nodeset_iterator_init(&iter, ready_set); + while( (irn = ir_nodeset_iterator_next(&iter)) != NULL) { if (! arch_irn_class_is(arch_env, irn, branch)) { only_branches_left = 0; - nodeset_break(ready_set); break; } } - if(only_branches_left) { + if (only_branches_left) { /* at last: schedule branches */ - irn = nodeset_first(ready_set); - nodeset_break(ready_set); + ir_nodeset_iterator_init(&iter, ready_set); + irn = ir_nodeset_iterator_next(&iter); } else { do { - // take 1 random node - int n = rand() % pset_count(ready_set); + /* take 1 random node */ + int n = rand() % ir_nodeset_size(ready_set); int i = 0; - for(irn = nodeset_first(ready_set); irn; irn = nodeset_next(ready_set)) { + ir_nodeset_iterator_init(&iter, ready_set); + while ((irn = ir_nodeset_iterator_next(&iter)) != NULL) { if(i == n) { - nodeset_break(ready_set); break; } ++i; @@ -51,18 +77,23 @@ static ir_node *random_select(void *block_env, nodeset *ready_set, nodeset *live return irn; } -static void *random_init_graph(const list_sched_selector_t *vtab, const arch_env_t *arch_env, ir_graph *irg) +static void *random_init_graph(const list_sched_selector_t *vtab, const be_irg_t *birg) { - srand(time(0)); - return (void *)arch_env; + (void) vtab; + /* Using time(NULL) as a seed here gives really random results, + but is NOT deterministic which makes debugging impossible. + Moreover no-one want non-deterministic compilers ... */ + srand(0x4711); + return (void *) be_get_birg_arch_env(birg); } -static void *random_init_block(void *graph_env, ir_node *bl) +static void *random_init_block(void *graph_env, ir_node *block) { + (void) block; return graph_env; } -static const list_sched_selector_t random_selector_struct = { +const list_sched_selector_t random_selector = { random_init_graph, random_init_block, random_select, @@ -74,5 +105,3 @@ static const list_sched_selector_t random_selector_struct = { NULL, /* finish_block */ NULL /* finish_graph */ }; - -const list_sched_selector_t *random_selector = &random_selector_struct;