# include "obst.h"
# include "irhooks.h"
# include "irtools.h"
+# include "array.h"
-/* * *
- * local values
- * * */
-
-
-/** dynamic array to hold all modes */
+/** Obstack to hold all modes. */
static struct obstack modes;
-/** number of defined modes */
+/** Number of defined modes. */
static int num_modes = 0;
-/* * *
- * local functions
- * * */
+/** The list of all currently existing modes. */
+static ir_mode **mode_list;
/**
* Compare modes that don't need to have their code field
*
* TODO: Add other fields
**/
-INLINE static int modes_are_equal(const ir_mode *m, const ir_mode *n) {
+static INLINE int modes_are_equal(const ir_mode *m, const ir_mode *n) {
if (m == n) return 1;
if (m->sort == n->sort &&
m->arithmetic == n->arithmetic &&
return 0;
}
-/*
- * calculates the next obstack address
- */
-static void *next_obstack_adr(struct obstack *o, void *p, size_t s) {
- PTR_INT_TYPE adr = PTR_TO_INT((char *)p);
- int mask = obstack_alignment_mask(o);
-
- adr += s + mask;
-
- return INT_TO_PTR(adr & ~mask);
-}
-
/**
* searches the modes obstack for the given mode and returns
* a pointer on an equal mode already in the array, NULL if
* none found
*/
static ir_mode *find_mode(const ir_mode *m) {
- ir_mode *n, *nn;
- struct _obstack_chunk *p;
-
- p = modes.chunk;
- n = (ir_mode *)p->contents;
- nn = next_obstack_adr(&modes, n, sizeof(*n));
- for (; (char *)nn <= modes.next_free;) {
- assert(is_mode(n));
+ int i;
+ for (i = ARR_LEN(mode_list) - 1; i >= 0; --i) {
+ ir_mode *n = mode_list[i];
if (modes_are_equal(n, m))
return n;
-
- n = nn;
- nn = next_obstack_adr(&modes, n, sizeof(*n));
}
+ return NULL;
+}
- for (p = p->prev; p; p = p->prev) {
- n = (ir_mode *)p->contents;
- nn = next_obstack_adr(&modes, n, sizeof(*n));
- for (; (char *)nn < p->limit;) {
- assert(is_mode(n));
- if (modes_are_equal(n, m))
- return n;
-
- n = nn;
- nn = next_obstack_adr(&modes, n, sizeof(*n));
- }
+#ifdef FIRM_STATISTICS
+/* return the mode index, only needed for statistics */
+int stat_find_mode_index(const ir_mode *m) {
+ int i;
+ for (i = ARR_LEN(mode_list) - 1; i >= 0; --i) {
+ ir_mode *n = mode_list[i];
+ if (modes_are_equal(n, m))
+ return i;
}
+ return -1;
+}
+/* return the mode for a given index, only needed for statistics */
+ir_mode *stat_mode_for_index(int idx) {
+ if (0 <= idx && idx < ARR_LEN(mode_list))
+ return mode_list[idx];
return NULL;
}
+#endif
/**
* sets special values of modes
/* copy mode struct to modes array */
mode = (ir_mode *)obstack_copy(&modes, new_mode, sizeof(*mode));
+ ARR_APP1(ir_mode*, mode_list, mode);
mode->kind = k_ir_mode;
if (num_modes >= irm_max) {
ir_mode newmode;
obstack_init(&modes);
+ mode_list = NEW_ARR_F(ir_mode*, 0);
num_modes = 0;
/* initialize predefined modes */
void finish_mode(void) {
obstack_free(&modes, 0);
+ DEL_ARR_F(mode_list);
mode_T = NULL;
mode_X = NULL;