summaryrefslogtreecommitdiff
path: root/regscope.h
blob: 427606460f6d63186569d1f1afc4106701b7765a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "stack-man.h"
#include "simplex86.h"

typedef struct reg_alloc_t reg_alloc_t;
typedef struct reg_status_t reg_status_t;
typedef struct reg_pool_t reg_pool_t;

#define MAX_REGISTERS (16)
#define MAX_SPILLS    (16)

struct reg_pool_t
{
    int         n_registers;
    int         bytes_per_reg;
    op_t	move_instruction;
    reg_t       registers[MAX_REGISTERS];
};

struct reg_status_t
{
    int		allocated;
    int		spillable;
    int		n_spills;
    int		spill_offsets[MAX_SPILLS];
};

struct reg_alloc_t
{
    reg_status_t	status[MAX_REGISTERS];
    const reg_pool_t *	pool;
    stack_man_t *	stack;
    fragment_t *	fragment;
};

void
reg_alloc_init (reg_alloc_t *ra,
		fragment_t *frag,
		stack_man_t *stack,
		const reg_pool_t *reg_pool);

/* Calling this indicates that the registers given will not be
 * needed until the corresponding reg_alloc_end_spill().
 */
void
reg_alloc_begin_spill (reg_alloc_t *ra, reg_t reg, ...);

void
reg_alloc_end_spill (reg_alloc_t *ra, reg_t reg, ...);

/* This allocates a register. Calliing this function indicates that
 * the register in question will be freed before the current 
 * begin/end_spill group ends.
 */
reg_t
reg_alloc_alloc_local (reg_alloc_t *ra);

/* This resurrects a register that has been freed, but is known
 * to still contain a useful value. The allocation is non-local,
 * so it is allowed to survive the current begin/end_spill group.
 *
 * The returned register may or may not be the same as the
 * input register.
 */
reg_t
reg_alloc_alloc_preserve (reg_alloc_t *ra, reg_t reg);

/* Allocates a register. The allocation is non-local, so it
 * is allowed to survive the current begin/end_spill group.
 */
reg_t
reg_alloc_alloc (reg_alloc_t *ra);

void
reg_alloc_free (reg_alloc_t *ra, reg_t reg);