#include "mcg.h"
#include "bigraph.h"
+#include "set.h"
#include <limits.h>
/* This is based around the elegant graph colouring algorithm here:
static struct heap anode_heap;
static struct graph interferenceg;
static struct graph preferenceg;
-static ARRAYOF(struct anode) vertices;
+static struct set vertices;
static ARRAYOF(struct anode) simplified;
#if 0
struct assignment
}
}
- for (i=0; i<vertices.count; i++)
{
- struct anode* anode = vertices.item[i];
- fprintf(regalloc_dot_file, "\t\"");
- dump_anode(anode);
- fprintf(regalloc_dot_file, "\" [color=green];\n");
+ struct set_iterator sit = {};
+ while (set_next(&vertices, &sit))
+ {
+ struct anode* anode = sit.item;
+ fprintf(regalloc_dot_file, "\t\"");
+ dump_anode(anode);
+ fprintf(regalloc_dot_file, "\" [color=green];\n");
+ }
}
fprintf(regalloc_dot_file, "}\n");
{
int i;
- vertices.count = 0;
+ set_reset(&vertices);
{
struct vertex_iterator vit = {};
while (graph_next_vertex(&interferenceg, &vit))
- array_appendu(&vertices, vit.data);
+ set_add(&vertices, vit.data);
}
{
struct vertex_iterator vit = {};
while (graph_next_vertex(&preferenceg, &vit))
- array_appendu(&vertices, vit.data);
+ set_add(&vertices, vit.data);
}
}
static void assign_registers(void)
{
- int i;
- for (i=0; i<vertices.count; i++)
- {
- struct anode* anode = vertices.item[i];
- }
}
void pass_register_allocator(void)
--- /dev/null
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include "set.h"
+
+void set_reset(struct set* s)
+{
+ hashtable_reset(&s->table);
+}
+
+void set_add(struct set* s, void* item)
+{
+ hashtable_put(&s->table, item, item);
+}
+
+bool set_remove(struct set* s, void* item)
+{
+ return hashtable_remove(&s->table, item);
+}
+
+bool set_contains(struct set* s, void* item)
+{
+ return hashtable_contains(&s->table, item);
+}
+
+void* set_pop(struct set* s)
+{
+ return hashtable_pop(&s->table);
+}
+
+void* set_next(struct set* s, struct set_iterator* sit)
+{
+ sit->item = hashtable_next(&s->table, &sit->hit);
+ return sit->item;
+}
+
--- /dev/null
+#ifndef SET_H
+#define SET_H
+
+/* A hashtable-based identity set. */
+
+#include "hashtable.h"
+
+struct set
+{
+ struct hashtable table;
+};
+
+extern void set_reset(struct set* s);
+
+extern void set_add(struct set* s, void* item);
+extern bool set_remove(struct set* s, void* item);
+extern bool set_contains(struct set* s, void* item);
+extern void* set_pop(struct set* s);
+
+struct set_iterator
+{
+ /* Public */
+ void* item;
+
+ /* Private */
+ struct hashtable_iterator hit;
+};
+
+extern void* set_next(struct set* s, struct set_iterator* sit);
+
+#endif
+