+#undef DUMP_ALLOCATED
+#undef DUMP_LOCALIZED
+
+#define N_PHASES 256
+
+typedef struct _be_graph_info_t {
+ bitset_t *applied_phases;
+} be_graph_info_t;
+
+static size_t be_info_offset = 0;
+
+#define get_irg_be_info(irg) get_irg_data(irg, be_graph_info_t, be_info_offset)
+
+static int phase_ids = 1;
+static struct obstack obst;
+
+int phase_register(phase_t *phase)
+{
+ phase->id = phase_ids;
+ return phase_ids++;
+}
+
+void phase_applied(const ir_graph *irg, const phase_t *phase)
+{
+ be_graph_info_t *info = get_irg_be_info(irg);
+
+ if(!info->applied_phases)
+ info->applied_phases = bitset_obstack_alloc(&obst, N_PHASES);
+
+ bitset_set(info->applied_phases, phase->id);
+}
+
+int phase_depends_on(const ir_graph *irg, const phase_t *phase, int n, ...)
+{
+ int errors = 0;
+ int i;
+ va_list args;
+
+ if(n > 0) {
+ const be_graph_info_t *info = get_irg_be_info(irg);
+ const bitset_t *applied_phases = info->applied_phases;
+
+ va_start(args, n);
+
+ for(i = 0; i < n; ++i) {
+ const phase_t *dep_phase = va_arg(args, const phase_t *);
+
+ if(!applied_phases || !bitset_is_set(applied_phases, dep_phase->id)) {
+ errors++;
+ fprintf(stderr, "phase dependency unfulfilled: \"%s\" depends on \"%s\"\n",
+ phase->name, dep_phase->name);
+ }
+ }
+
+ va_end(args);
+
+ assert(errors > 0 && "There were phase dependency errors");
+ }
+
+ return errors;
+}
+