bestat.c 2.54 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
3
4
5
/**
 * This file calls the corresponding statistic functions for
 * some backend statistics.
 * $Id$
 */
6
7
8
9
10
11
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef FIRM_STATISTICS

12
13
14
15
16
#include "irnode_t.h"
#include "irprintf.h"
#include "irgwalk.h"
#include "irhooks.h"
#include "dbginfo_t.h"
17
#include "firmstat_t.h"
18
#include "irtools.h"
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

#include "bestat.h"
#include "belive_t.h"
#include "besched.h"

/**
 * Collect reg pressure statistics per block and per class.
 */
static void stat_reg_pressure_block(ir_node *block, void *env) {
	be_irg_t         *birg = env;
	const arch_env_t *aenv = birg->main_env->arch_env;
	int i, n = arch_isa_get_n_reg_class(aenv->isa);

	for (i = 0; i < n; i++) {
		const arch_register_class_t *cls = arch_isa_get_reg_class(aenv->isa, i);
		ir_node  *irn;
35
		pset     *live_nodes = pset_new_ptr(64);
36
37
38
39
40
41
42
43
44
45
46
47
48
49
		int       max_live;

		live_nodes = be_liveness_end_of_block(aenv, cls, block, live_nodes);
		max_live   = pset_count(live_nodes);

		sched_foreach_reverse(block, irn) {
			int cnt;

			live_nodes = be_liveness_transfer(aenv, cls, irn, live_nodes);
			cnt        = pset_count(live_nodes);

			max_live = cnt < max_live ? max_live : cnt;
		}

50
		stat_be_block_regpressure(birg->irg, block, MIN(max_live, 5), cls->name);
51
52
53
54
	}
}

void be_do_stat_reg_pressure(be_irg_t *birg) {
55
56
57
58
59
	if (stat_is_active()) {
		be_liveness(birg->irg);
		/* Collect register pressure information for each block */
		irg_block_walk_graph(birg->irg, stat_reg_pressure_block, NULL, birg);
	}
60
}
61
62
63
64
65

/**
 * Notify statistic module about amount of ready nodes.
 */
void be_do_stat_sched_ready(ir_node *block, nodeset *ready_set) {
66
67
68
	if (stat_is_active()) {
		stat_be_block_sched_ready(get_irn_irg(block), block, nodeset_count(ready_set));
	}
69
}
70

Christian Würdig's avatar
Christian Würdig committed
71
72
73
74
/**
 * Pass information about a perm to the statistic module.
 */
void be_do_stat_perm(const char *class_name, int n_regs, ir_node *perm, ir_node *block, int n, int real_size) {
75
76
77
	if (stat_is_active()) {
		stat_be_block_stat_perm(class_name, n_regs, perm, block, n, real_size);
	}
Christian Würdig's avatar
Christian Würdig committed
78
79
80
81
82
83
}

/**
 * Pass information about a cycle or chain in a perm to the statistic module.
 */
void be_do_stat_permcycle(const char *class_name, ir_node *perm, ir_node *block, int is_chain, int n_elems, int n_ops) {
84
85
86
	if (stat_is_active()) {
		stat_be_block_stat_permcycle(class_name, perm, block, is_chain, n_elems, n_ops);
	}
Christian Würdig's avatar
Christian Würdig committed
87
88
}

89
90
91
92
#else

void (be_do_stat_reg_pressure)(be_irg_t *birg) {}
void (be_do_stat_sched_ready)(ir_node *block, nodeset *ready_set) {}
Christian Würdig's avatar
Christian Würdig committed
93
void (be_do_stat_perm)(const char *class_name, int n_regs, ir_node *perm, ir_node *block, int n, int real_size) {}
94
95

#endif /* FIRM_STATISTICS */