diff options
author | Søren Sandmann <ssp@redhat.com> | 2013-12-23 14:12:31 -0500 |
---|---|---|
committer | Søren Sandmann <ssp@redhat.com> | 2013-12-23 14:12:31 -0500 |
commit | 9c77ac187936acbe4ed3acf51686ea6de54dff59 (patch) | |
tree | 4b9952b6a6490dd3284471296b21fe5d42e426f2 /regscope.h | |
parent | 0e132575548120288498a1f4bb23befe95ec32b1 (diff) |
The millionth register allocator. This time with scoped spills
Diffstat (limited to 'regscope.h')
-rw-r--r-- | regscope.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/regscope.h b/regscope.h new file mode 100644 index 0000000..4276064 --- /dev/null +++ b/regscope.h @@ -0,0 +1,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); |