blob: cf6e595ad671c71416775bd973cdbeb5eea0c622 (
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
|
#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);
}
|