X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firmode.c;h=628ed42b9840244856f4194774f634a40c263b71;hb=336e12655908a05add9a504c5f7741c8b71d8506;hp=eba8facf25ece726de99853d5492f3185fcefad0;hpb=b2883fe45bd4299e88e841cceb78097293fcdae0;p=libfirm diff --git a/ir/ir/irmode.c b/ir/ir/irmode.c index eba8facf2..628ed42b9 100644 --- a/ir/ir/irmode.c +++ b/ir/ir/irmode.c @@ -43,21 +43,16 @@ # 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 @@ -65,7 +60,7 @@ static int num_modes = 0; * * 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 && @@ -78,54 +73,40 @@ INLINE static int modes_are_equal(const ir_mode *m, const ir_mode *n) { 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 @@ -263,6 +244,7 @@ static ir_mode *register_mode(const ir_mode *new_mode) { /* 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) { @@ -641,6 +623,7 @@ void init_mode(void) { ir_mode newmode; obstack_init(&modes); + mode_list = NEW_ARR_F(ir_mode*, 0); num_modes = 0; /* initialize predefined modes */ @@ -922,6 +905,7 @@ int mode_wrap_around(const ir_mode *mode) { void finish_mode(void) { obstack_free(&modes, 0); + DEL_ARR_F(mode_list); mode_T = NULL; mode_X = NULL;