aboutsummaryrefslogtreecommitdiff
path: root/regalloc.c
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2018-01-05 23:42:24 +0100
committertomsmeding <tom.smeding@gmail.com>2018-01-05 23:42:24 +0100
commit3272b5d83d2e2167eed24748557df88bd66584ee (patch)
tree6b8f1574f6d6a44e11b74903516286f6249cb0b7 /regalloc.c
parenta298cb75c4f586b83b304c7dc66cb555693ea1b8 (diff)
There's actually a chance that, correctly stringified, this will work
Diffstat (limited to 'regalloc.c')
-rw-r--r--regalloc.c33
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);
+}