bechordal_t.h 4.92 KB
Newer Older
Sebastian Hack's avatar
Sebastian Hack committed
1
2

/**
3
 * Internal data structures for the chordal register allocator.
Sebastian Hack's avatar
Sebastian Hack committed
4
5
6
7
8
9
10
 * @author Sebastian Hack
 * @date 25.1.2005
 */

#ifndef _BECHORDAL_T_H
#define _BECHORDAL_T_H

11
12
13
#include "firm_types.h"
#include "firm_config.h"

14
15
16
17
#include <stdlib.h>

#include "bitset.h"
#include "list.h"
Sebastian Hack's avatar
Sebastian Hack committed
18
#include "obst.h"
19
20
21
22
#include "pset.h"
#include "pmap.h"
#include "set.h"

Sebastian Hack's avatar
Sebastian Hack committed
23
24
#include "execfreq.h"

Sebastian Hack's avatar
Sebastian Hack committed
25
#include "be_t.h"
Sebastian Hack's avatar
Sebastian Hack committed
26
27
#include "beifg.h"
#include "bera.h"
Sebastian Hack's avatar
Sebastian Hack committed
28
#include "bearch.h"
Sebastian Hack's avatar
Sebastian Hack committed
29
30
#include "bechordal.h"
#include "beirgmod.h"
Sebastian Hack's avatar
Sebastian Hack committed
31
#include "belive.h"
32
#include "beirg.h"
33

Sebastian Hack's avatar
Sebastian Hack committed
34
35
typedef struct _be_ra_chordal_opts_t be_ra_chordal_opts_t;

36
37
38
/** Defines an invalid register index. */
#define NO_COLOR (-1)

Sebastian Hack's avatar
Sebastian Hack committed
39
40
41
42
/**
 * A liveness interval border.
 */
typedef struct _border_t {
43
44
45
46
47
48
49
50
51
52
	unsigned magic;                 /**< A magic number for checking. */
	struct list_head list;          /**< list head for queuing. */
	struct _border_t *other_end;    /**< The other end of the border. */
	ir_node *irn;                   /**< The node. */
	unsigned step;                  /**< The number equal to the interval border. */
	unsigned pressure;              /**< The pressure at this interval border. (The border itself is counting). */
	unsigned is_def : 1;            /**< Does this border denote a use or a def. */
	unsigned is_real : 1;           /**< Is the def/use real? Or is it just inserted
                                        at block beginnings or ends to ensure that inside
                                        a block, each value has one begin and one end. */
Sebastian Hack's avatar
Sebastian Hack committed
53
54
} border_t;

55
56
57
58
/**
 * Environment for each of the chordal register allocator phases
 */
struct _be_chordal_env_t {
59
60
	struct obstack obst;                /**< An obstack for temporary storage. */
	be_ra_chordal_opts_t *opts;         /**< A pointer to the chordal ra options. */
61
	be_irg_t *birg;                     /**< Back-end IRG session. */
62
63
64
65
66
67
	ir_graph *irg;                      /**< The graph under examination. */
	const arch_register_class_t *cls;   /**< The current register class. */
	pmap *border_heads;                 /**< Maps blocks to border heads. */
	be_ifg_t *ifg;                      /**< The interference graph. */
	void *data;                         /**< Some pointer, to which different phases can attach data to. */
	bitset_t *ignore_colors;            /**< A set of colors which shall be ignored in register allocation. */
68
	DEBUG_ONLY(firm_dbg_module_t *dbg;) /**< Debug module for the chordal register allocator. */
69
70
};

Daniel Grund's avatar
Daniel Grund committed
71
static INLINE struct list_head *_get_block_border_head(const be_chordal_env_t *inf, ir_node *bl) {
72
73
74
75
76
  return pmap_get(inf->border_heads, bl);
}

#define get_block_border_head(info, bl)     _get_block_border_head(info, bl)

Sebastian Hack's avatar
Sebastian Hack committed
77
#define foreach_border_head(head, pos)		list_for_each_entry_reverse(border_t, pos, head, list)
78
79
#define border_next(b)                      (list_entry((b)->list.next, border_t, list))
#define border_prev(b)                      (list_entry((b)->list.prev, border_t, list))
80

Sebastian Hack's avatar
Sebastian Hack committed
81
#define chordal_has_class(chordal_env, irn) \
Sebastian Hack's avatar
Sebastian Hack committed
82
	arch_irn_consider_in_reg_alloc(chordal_env->birg->main_env->arch_env, chordal_env->cls, irn)
Daniel Grund's avatar
Daniel Grund committed
83

Sebastian Hack's avatar
Sebastian Hack committed
84
int nodes_interfere(const be_chordal_env_t *env, const ir_node *a, const ir_node *b);
Daniel Grund's avatar
Daniel Grund committed
85

Sebastian Hack's avatar
Sebastian Hack committed
86
void be_ra_chordal_color(be_chordal_env_t *chordal_env);
Daniel Grund's avatar
Daniel Grund committed
87

Sebastian Hack's avatar
Sebastian Hack committed
88
89
90
91
92
93
/**
 * Check a register allocation obtained with the chordal register allocator.
 * @param chordal_env The chordal environment.
 */
void be_ra_chordal_check(be_chordal_env_t *chordal_env);

Sebastian Hack's avatar
Sebastian Hack committed
94
95
enum {
	/* spill method */
96
	BE_CH_SPILL_BELADY    = 1,
97
	BE_CH_SPILL_MORGAN    = 2,
98
	BE_CH_SPILL_REMAT     = 3,
99

Sebastian Hack's avatar
Sebastian Hack committed
100
	/* Dump flags */
101
102
	BE_CH_DUMP_NONE       = (1 << 0),
	BE_CH_DUMP_SPILL      = (1 << 1),
Sebastian Hack's avatar
Sebastian Hack committed
103
104
105
106
107
108
	BE_CH_DUMP_LIVE       = (1 << 2),
	BE_CH_DUMP_COLOR      = (1 << 3),
	BE_CH_DUMP_COPYMIN    = (1 << 4),
	BE_CH_DUMP_SSADESTR   = (1 << 5),
	BE_CH_DUMP_TREE_INTV  = (1 << 6),
	BE_CH_DUMP_CONSTR     = (1 << 7),
Matthias Braun's avatar
Matthias Braun committed
109
110
111
112
	BE_CH_DUMP_SPILLSLOTS = (1 << 8),
	BE_CH_DUMP_LOWER      = (1 << 9),
	BE_CH_DUMP_APPEL      = (1 << 10),
	BE_CH_DUMP_ALL        = 2 * BE_CH_DUMP_APPEL - 1,
Daniel Grund's avatar
Daniel Grund committed
113

Sebastian Hack's avatar
Sebastian Hack committed
114
	/* ifg flavor */
115
116
117
118
119
120
	BE_CH_IFG_STD     = 1,
	BE_CH_IFG_FAST    = 2,
	BE_CH_IFG_CLIQUE  = 3,
	BE_CH_IFG_POINTER = 4,
	BE_CH_IFG_LIST    = 5,
	BE_CH_IFG_CHECK   = 6,
121

122
	/* lower perm options */
123
124
	BE_CH_LOWER_PERM_SWAP   = 1,
	BE_CH_LOWER_PERM_COPY   = 2,
Christian Würdig's avatar
Christian Würdig committed
125
126
127
128
129

	/* verify options */
	BE_CH_VRFY_OFF    = 1,
	BE_CH_VRFY_WARN   = 2,
	BE_CH_VRFY_ASSERT = 3,
Sebastian Hack's avatar
Sebastian Hack committed
130
};
Sebastian Hack's avatar
Sebastian Hack committed
131

Sebastian Hack's avatar
Sebastian Hack committed
132
struct _be_ra_chordal_opts_t {
133
	int dump_flags;
Sebastian Hack's avatar
Sebastian Hack committed
134
135
	int spill_method;
	int ifg_flavor;
136
	int lower_perm_opt;
Christian Würdig's avatar
Christian Würdig committed
137
	int vrfy_option;
Sebastian Hack's avatar
Sebastian Hack committed
138

Sebastian Hack's avatar
Sebastian Hack committed
139
140
	char ilp_server[128];
	char ilp_solver[128];
Sebastian Hack's avatar
Sebastian Hack committed
141
};
Sebastian Hack's avatar
Sebastian Hack committed
142

Sebastian Hack's avatar
Sebastian Hack committed
143
144
145
146
147
148
149
150
/**
 * Open a file whose name is composed from the graph's name and the current register class.
 * @note The name of the file will be prefix(ifg_name)_(reg_class_name).suffix
 * @param prefix The file name's prefix.
 * @param suffix The file name's ending (the . is inserted automatically).
 * @return       A text file opened for writing.
 */
FILE *be_chordal_open(const be_chordal_env_t *env, const char *prefix, const char *suffix);
Sebastian Hack's avatar
Sebastian Hack committed
151

Sebastian Hack's avatar
Sebastian Hack committed
152
153
void be_pre_spill_prepare_constr(be_chordal_env_t *cenv);

Sebastian Hack's avatar
Sebastian Hack committed
154
#endif /* _BECHORDAL_T_H */