diff options
Diffstat (limited to 'reggroups.h')
-rw-r--r-- | reggroups.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/reggroups.h b/reggroups.h new file mode 100644 index 0000000..b8c0dc7 --- /dev/null +++ b/reggroups.h @@ -0,0 +1,58 @@ +#include "stack-man.h" +#include "simplex86.h" + +typedef struct reg_alloc_t reg_alloc_t; +typedef struct reg_group_t reg_group_t; +typedef struct reg_pool_t reg_pool_t; + +#define MAX_REGISTERS (64) +#define MAX_GROUPS (16) + +struct reg_pool_t +{ + int n_registers; + int register_size; + reg_t registers[MAX_REGISTERS]; +}; + +struct reg_group_t +{ + const char *name; + int allocated[MAX_REGISTERS]; + int spill_offset[MAX_REGISTERS]; /* -1 if not spilled */ +}; + +struct reg_alloc_t +{ + const reg_pool_t *reg_pool; + reg_group_t groups[MAX_GROUPS]; + reg_group_t *active; +}; + +void +reg_alloc_init (reg_alloc_t *ra, stack_man_t *stack, const reg_pool_t *reg_pool); + +void +reg_alloc_switch_group (reg_alloc_t *ra, const char *name); + +void +reg_alloc_free_group (reg_alloc_t *ra, const char *name); + +/* After switching back to a group, this should be called for + * all registers that will be used again before switching away. + */ +void +reg_alloc_reload (reg_alloc_t *ra, op_t reg, ...); + +/* allocate some register within the current group */ +reg_t +reg_alloc_alloc (reg_alloc_t *ra); + +/* @reg becomes allocated in the current group, though it + * may be moved to another register + */ +reg_t +reg_alloc_preserve (reg_alloc_t *ra, reg_t reg); + +void +reg_alloc_free (reg_alloc_t *ra, reg_t reg); |