<commit_before>/*
 * Copyright (C) 1995-2007 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.
 */

/**
 * @brief   Use the strong normal form theorem (though it does not hold)
 * @author  <NAME>
 * @version $Id: beschedrand.c 14604 2007-06-18 14:07:07Z matze $
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>

#include "besched_t.h"
#include "belistsched.h"
#include "belive_t.h"
#include "beutil.h"
#include "irtools.h"
#include "irgwalk.h"


// XXX there is no one time init for schedulers
//#define NORMAL_DBG


static const arch_env_t *cur_arch_env;


static ir_node *normal_select(void *block_env, ir_nodeset_t *ready_set,
                              ir_nodeset_t *live_set)
{
	ir_nodeset_iterator_t iter;
	ir_node*  block;
	ir_node*  irn;
	ir_node** sched;
	int sched_count;

	(void)block_env;
	(void)live_set;

	ir_nodeset_iterator_init(&iter, ready_set);
	irn = ir_nodeset_iterator_next(&iter);
	block = get_nodes_block(irn);
	sched = get_irn_link(block);
	sched_count = ARR_LEN(sched);
	for (; sched_count-- != 0; ++sched) {
		ir_node* irn = *sched;
		if (ir_nodeset_contains(ready_set, irn) &&
				!arch_irn_class_is(cur_arch_env, irn, branch)) {
#if defined NORMAL_DBG
			ir_fprintf(stderr, "scheduling %+F\n", irn);
#endif
			return irn;
		}
	}

	return irn;
}


typedef struct irn_cost_pair {
	ir_node* irn;
	int      cost;
} irn_cost_pair;


static int cost_cmp(const void* a, const void* b)
{
	const irn_cost_pair* a1 = a;
	const irn_cost_pair* b1 = b;
	return b1->cost - a1->cost;
}


typedef struct flag_and_cost {
	int no_root;
	irn_cost_pair costs[];
} flag_and_cost;


static int count_result(const ir_node* irn)
{
	const ir_mode* mode = get_irn_mode(irn);
	return
		mode != mode_M &&
		mode != mode_X &&
		!arch_irn_is(cur_arch_env, irn, ignore);
}


static int normal_tree_cost(ir_node* irn)
{
	flag_and_cost* fc    = get_irn_link(irn);
	ir_node*       block = get_nodes_block(irn);
	int            arity = get_irn_arity(irn);
	int            cost_max  = 0;
	int            count_max = 0;
	int            n_res;
	int            cost;

	if (fc == NULL) {
		irn_cost_pair* costs;
		int            i;

		fc = malloc(sizeof(*fc) + sizeof(*fc->costs) * arity);
		fc->no_root = 0;
		costs = fc->costs;

		for (i = 0; i < arity; ++i) {
			ir_node* pred = get_irn_n(irn, i);
			int cost;

			if (is_Phi(irn) || get_irn_mode(pred) == mode_M) {
				cost = 0;
			} else if (get_nodes_block(pred) != block) {
				cost = 1;
			} else {
				cost = normal_tree_cost(pred);
				flag_and_cost* pred_fc = get_irn_link(pred);
				pred_fc->no_root = 1;
#if defined NORMAL_DBG
				ir_fprintf(stderr, "%+F says that %+F is no root\n", irn, pred);
#endif
			}

			costs[i].irn  = pred;
			costs[i].cost = cost;

			if (cost > cost_max) {
				cost_max  = cost;
				count_max = 1;
			} else if (cost == cost_max) {
				++count_max;
			}
		}

		qsort(costs, arity, sizeof(*costs), cost_cmp);
		set_irn_link(irn, fc);
	} else {
		irn_cost_pair* costs = fc->costs;
		int            i;

		if (arity > 0) {
			cost_max = costs[0].cost;

			for (i = 0; i < arity; ++i) {
				if (costs[i].cost < cost_max) break;
				++count_max;
			}
		}<commit_msg>C99 feature removed<commit_after>/*
 * Copyright (C) 1995-2007 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.
 */

/**
 * @brief   Use the strong normal form theorem (though it does not hold)
 * @author  <NAME>
 * @version $Id: beschedrand.c 14604 2007-06-18 14:07:07Z matze $
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>

#include "besched_t.h"
#include "belistsched.h"
#include "belive_t.h"
#include "beutil.h"
#include "irtools.h"
#include "irgwalk.h"


// XXX there is no one time init for schedulers
//#define NORMAL_DBG


static const arch_env_t *cur_arch_env;


static ir_node *normal_select(void *block_env, ir_nodeset_t *ready_set,
                              ir_nodeset_t *live_set)
{
	ir_nodeset_iterator_t iter;
	ir_node*  block;
	ir_node*  irn;
	ir_node** sched;
	int sched_count;

	(void)block_env;
	(void)live_set;

	ir_nodeset_iterator_init(&iter, ready_set);
	irn = ir_nodeset_iterator_next(&iter);
	block = get_nodes_block(irn);
	sched = get_irn_link(block);
	sched_count = ARR_LEN(sched);
	for (; sched_count-- != 0; ++sched) {
		ir_node* irn = *sched;
		if (ir_nodeset_contains(ready_set, irn) &&
				!arch_irn_class_is(cur_arch_env, irn, branch)) {
#if defined NORMAL_DBG
			ir_fprintf(stderr, "scheduling %+F\n", irn);
#endif
			return irn;
		}
	}

	return irn;
}


typedef struct irn_cost_pair {
	ir_node* irn;
	int      cost;
} irn_cost_pair;


static int cost_cmp(const void* a, const void* b)
{
	const irn_cost_pair* a1 = a;
	const irn_cost_pair* b1 = b;
	return b1->cost - a1->cost;
}


typedef struct flag_and_cost {
	int no_root;
	irn_cost_pair costs[];
} flag_and_cost;


static int count_result(const ir_node* irn)
{
	const ir_mode* mode = get_irn_mode(irn);
	return
		mode != mode_M &&
		mode != mode_X &&
		!arch_irn_is(cur_arch_env, irn, ignore);
}


static int normal_tree_cost(ir_node* irn)
{
	flag_and_cost* fc    = get_irn_link(irn);
	ir_node*       block = get_nodes_block(irn);
	int            arity = get_irn_arity(irn);
	int            cost_max  = 0;
	int            count_max = 0;
	int            n_res;
	int            cost;

	if (fc == NULL) {
		irn_cost_pair* costs;
		int            i;

		fc = malloc(sizeof(*fc) + sizeof(*fc->costs) * arity);
		fc->no_root = 0;
		costs = fc->costs;

		for (i = 0; i < arity; ++i) {
			ir_node* pred = get_irn_n(irn, i);
			int cost;

			if (is_Phi(irn) || get_irn_mode(pred) == mode_M) {
				cost = 0;
			} else if (get_nodes_block(pred) != block) {
				cost = 1;
			} else {
				flag_and_cost* pred_fc;

				cost = normal_tree_cost(pred);
				pred_fc = get_irn_link(pred);
				pred_fc->no_root = 1;
#if defined NORMAL_DBG
				ir_fprintf(stderr, "%+F says that %+F is no root\n", irn, pred);
#endif
			}

			costs[i].irn  = pred;
			costs[i].cost = cost;

			if (cost > cost_max) {
				cost_max  = cost;
				count_max = 1;
			} else if (cost == cost_max) {
				++count_max;
			}
		}

		qsort(costs, arity, sizeof(*costs), cost_cmp);
		set_irn_link(irn, fc);
	} else {
		irn_cost_pair* costs = fc->costs;
		int            i;

		if (arity > 0) {
			cost_max = costs[0].cost;

			for (i = 0; i < arity; ++i) {
				if (costs[i].cost < cost_max) break;
				++count_max;
			}
		}
{'fraction_non_alphanumeric': 0.11933016877637131, 'fraction_numerical': 0.011867088607594937, 'mean_word_length': 3.230340211935304, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3585856', 'n_tokens_mistral': 3213, 'n_tokens_neox': 2922, 'n_words': 785}