diff options
Diffstat (limited to 'regalloc.c')
-rw-r--r-- | regalloc.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/regalloc.c b/regalloc.c new file mode 100644 index 0000000..cf6e595 --- /dev/null +++ b/regalloc.c @@ -0,0 +1,33 @@ +#include <stdlib.h> +#include <assert.h> +#include "regalloc.h" + + +struct allocation* regalloc(const struct ir *ir) { + int maxreg = 0; + for (int i = 0; i < ir->len; i++) { + const struct irins *ins = ir->inss[i]; + + bool haveref[3]; + irins_which_refs(ins, haveref); + for (int ri = 0; ri < 3; ri++) { + if (haveref[ri] && ins->three_refs[ri].reg > maxreg) { + maxreg = ins->three_refs[ri].reg; + } + } + } + + struct allocation *alloc = malloc(sizeof(struct allocation)); + alloc->numregs = maxreg + 1; + alloc->allocs = malloc(alloc->numregs * sizeof(struct allocation_record)); + for (int i = 0; i < alloc->numregs; i++) { + alloc->allocs[i].spill = true; // lel + } + + return alloc; +} + +void allocation_delete(struct allocation *alloc) { + free(alloc->allocs); + free(alloc); +} |