X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firmode.c;h=8e2752bcbcd0179620504ac085d4958f75c2db6a;hb=fed1bdc07c9ec7b4d07a9243ad093c9fdd239fbd;hp=95a6e55b428930c8318d60d56cc7af1a01c420f1;hpb=a94cba60b644054b5f9f1983a6bd9d3f2d6f9142;p=libfirm diff --git a/ir/ir/irmode.c b/ir/ir/irmode.c index 95a6e55b4..8e2752bcb 100644 --- a/ir/ir/irmode.c +++ b/ir/ir/irmode.c @@ -22,10 +22,12 @@ # include +# include "irprog_t.h" # include "irmode_t.h" # include "ident.h" -# include "tv.h" +# include "tv_t.h" # include "obst.h" +# include "irhooks.h" #if 0 static long long count = 0; @@ -130,33 +132,37 @@ static void set_mode_values(ir_mode* mode) case irms_character: case irms_int_number: case irms_float_number: - mode->min = get_tarval_min(mode); - mode->max = get_tarval_max(mode); + mode->min = get_tarval_min(mode); + mode->max = get_tarval_max(mode); mode->null = get_tarval_null(mode); - mode->one = get_tarval_one(mode); + mode->one = get_tarval_one(mode); + mode->minus_one = get_tarval_minus_one(mode); break; case irms_internal_boolean: - mode->min = tarval_b_false; - mode->max = tarval_b_true; + mode->min = tarval_b_false; + mode->max = tarval_b_true; mode->null = tarval_b_false; - mode->one = tarval_b_true; + mode->one = tarval_b_true; + mode->minus_one = tarval_bad; break; case irms_reference: - mode->min = tarval_bad; - mode->max = tarval_bad; - mode->null = (get_mode_modecode(mode) == irm_P) ? tarval_P_void : tarval_bad; - mode->one = tarval_bad; + mode->min = tarval_bad; + mode->max = tarval_bad; + mode->null = get_tarval_null(mode); + mode->one = tarval_bad; + mode->minus_one = tarval_bad; break; case irms_auxiliary: case irms_memory: case irms_control_flow: - mode->min = tarval_bad; - mode->max = tarval_bad; + mode->min = tarval_bad; + mode->max = tarval_bad; mode->null = tarval_bad; - mode->one = tarval_bad; + mode->one = tarval_bad; + mode->minus_one = tarval_bad; break; } } @@ -195,44 +201,57 @@ ir_mode *mode_b; ir_mode *mode_P; /* machine specific modes */ -ir_mode *mode_P_mach; /* machine specific pointer mode */ +ir_mode *mode_P_code; /**< machine specific pointer mode for code addresses */ +ir_mode *mode_P_data; /**< machine specific pointer mode for data addresses */ /* * * * functions defined in irmode.h * * */ /* JNI access functions */ -INLINE ir_mode *get_modeT(void) { ANNOUNCE(); return mode_T; } -INLINE ir_mode *get_modeF(void) { ANNOUNCE(); return mode_F; } -INLINE ir_mode *get_modeD(void) { ANNOUNCE(); return mode_D; } -INLINE ir_mode *get_modeE(void) { ANNOUNCE(); return mode_E; } -INLINE ir_mode *get_modeBs(void) { ANNOUNCE(); return mode_Bs; } -INLINE ir_mode *get_modeBu(void) { ANNOUNCE(); return mode_Bu; } -INLINE ir_mode *get_modeHs(void) { ANNOUNCE(); return mode_Hs; } -INLINE ir_mode *get_modeHu(void) { ANNOUNCE(); return mode_Hu; } -INLINE ir_mode *get_modeIs(void) { ANNOUNCE(); return mode_Is; } -INLINE ir_mode *get_modeIu(void) { ANNOUNCE(); return mode_Iu; } -INLINE ir_mode *get_modeLs(void) { ANNOUNCE(); return mode_Ls; } -INLINE ir_mode *get_modeLu(void) { ANNOUNCE(); return mode_Lu; } -INLINE ir_mode *get_modeC(void) { ANNOUNCE(); return mode_C; } -INLINE ir_mode *get_modeU(void) { ANNOUNCE(); return mode_U; } -INLINE ir_mode *get_modeb(void) { ANNOUNCE(); return mode_b; } -INLINE ir_mode *get_modeP(void) { ANNOUNCE(); return mode_P; } -INLINE ir_mode *get_modeX(void) { ANNOUNCE(); return mode_X; } -INLINE ir_mode *get_modeM(void) { ANNOUNCE(); return mode_M; } -INLINE ir_mode *get_modeBB(void) { ANNOUNCE(); return mode_BB; } -INLINE ir_mode *get_modeANY(void) { ANNOUNCE(); return mode_ANY; } -INLINE ir_mode *get_modeBAD(void) { ANNOUNCE(); return mode_BAD; } +ir_mode *get_modeT(void) { ANNOUNCE(); return mode_T; } +ir_mode *get_modeF(void) { ANNOUNCE(); return mode_F; } +ir_mode *get_modeD(void) { ANNOUNCE(); return mode_D; } +ir_mode *get_modeE(void) { ANNOUNCE(); return mode_E; } +ir_mode *get_modeBs(void) { ANNOUNCE(); return mode_Bs; } +ir_mode *get_modeBu(void) { ANNOUNCE(); return mode_Bu; } +ir_mode *get_modeHs(void) { ANNOUNCE(); return mode_Hs; } +ir_mode *get_modeHu(void) { ANNOUNCE(); return mode_Hu; } +ir_mode *get_modeIs(void) { ANNOUNCE(); return mode_Is; } +ir_mode *get_modeIu(void) { ANNOUNCE(); return mode_Iu; } +ir_mode *get_modeLs(void) { ANNOUNCE(); return mode_Ls; } +ir_mode *get_modeLu(void) { ANNOUNCE(); return mode_Lu; } +ir_mode *get_modeC(void) { ANNOUNCE(); return mode_C; } +ir_mode *get_modeU(void) { ANNOUNCE(); return mode_U; } +ir_mode *get_modeb(void) { ANNOUNCE(); return mode_b; } +ir_mode *get_modeP(void) { ANNOUNCE(); return mode_P; } +ir_mode *get_modeX(void) { ANNOUNCE(); return mode_X; } +ir_mode *get_modeM(void) { ANNOUNCE(); return mode_M; } +ir_mode *get_modeBB(void) { ANNOUNCE(); return mode_BB; } +ir_mode *get_modeANY(void) { ANNOUNCE(); return mode_ANY; } +ir_mode *get_modeBAD(void) { ANNOUNCE(); return mode_BAD; } -ir_mode *(get_modeP_mach)(void) { +ir_mode *(get_modeP_code)(void) { ANNOUNCE(); - return __get_modeP_mach(); + return _get_modeP_code(); } -void (set_modeP_mach)(ir_mode *p) { +ir_mode *(get_modeP_data)(void) { ANNOUNCE(); - __set_modeP_mach(p); + return _get_modeP_data(); +} + +void set_modeP_code(ir_mode *p) { + assert(mode_is_reference(p)); + + mode_P_code = p; +} + +void set_modeP_data(ir_mode *p) { + assert(mode_is_reference(p)); + + mode_P_data = p; } /** @@ -240,7 +259,7 @@ void (set_modeP_mach)(ir_mode *p) { * * @param new_mode The new mode template. */ -static ir_mode *register_mode(const ir_mode* new_mode) +static ir_mode *register_mode(const ir_mode *new_mode) { ir_mode *mode = NULL; @@ -248,14 +267,18 @@ static ir_mode *register_mode(const ir_mode* new_mode) assert(new_mode); /* copy mode struct to modes array */ - mode = (ir_mode*)obstack_copy(&modes, new_mode, sizeof(ir_mode)); + mode = (ir_mode *)obstack_copy(&modes, new_mode, sizeof(*mode)); mode->kind = k_ir_mode; if (num_modes >= irm_max) mode->code = num_modes; num_modes++; + /* add the new mode to the irp list of modes */ + add_irp_mode(mode); + set_mode_values(mode); + hook_new_mode(new_mode, mode); return mode; } @@ -266,7 +289,7 @@ ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int sign, mode_arithmetic arithmetic, unsigned int modulo_shift ) { ir_mode mode_tmpl; - ir_mode *mode; + ir_mode *mode = NULL; mode_tmpl.name = new_id_from_str(name); mode_tmpl.sort = sort; @@ -279,8 +302,8 @@ ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int sign, mode_tmpl.tv_priv = NULL; mode = find_mode(&mode_tmpl); - if (mode) - { + if (mode) { + hook_new_mode(&mode_tmpl, mode); return mode; } @@ -292,15 +315,15 @@ ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int sign, case irms_memory: case irms_internal_boolean: assert(0 && "internal modes cannot be user defined"); - return NULL; + break; case irms_float_number: case irms_int_number: case irms_reference: case irms_character: - return register_mode(&mode_tmpl); + mode = register_mode(&mode_tmpl); } - return NULL; /* to shut up gcc */ + return mode; } /* @@ -310,7 +333,7 @@ ir_mode *new_ir_vector_mode(const char *name, mode_sort sort, int bit_size, unsi mode_arithmetic arithmetic, unsigned int modulo_shift ) { ir_mode mode_tmpl; - ir_mode *mode; + ir_mode *mode = NULL; mode_tmpl.name = new_id_from_str(name); mode_tmpl.sort = sort; @@ -323,8 +346,10 @@ ir_mode *new_ir_vector_mode(const char *name, mode_sort sort, int bit_size, unsi mode_tmpl.tv_priv = NULL; mode = find_mode(&mode_tmpl); - if (mode) + if (mode) { + hook_new_mode(&mode_tmpl, mode); return mode; + } if (num_of_elem <= 1) { assert(0 && "vector modes should have at least 2 elements"); @@ -339,36 +364,36 @@ ir_mode *new_ir_vector_mode(const char *name, mode_sort sort, int bit_size, unsi case irms_memory: case irms_internal_boolean: assert(0 && "internal modes cannot be user defined"); - return NULL; + break; case irms_reference: case irms_character: assert(0 && "only integer and floating point modes can be vectorized"); - return NULL; + break; case irms_float_number: assert(0 && "not yet implemented"); - return NULL; + break; case irms_int_number: - return register_mode(&mode_tmpl); + mode = register_mode(&mode_tmpl); } - return NULL; /* to shut up gcc */ + return mode; } -/* Functions for the direct access to all attributes od a ir_mode */ +/* Functions for the direct access to all attributes of an ir_mode */ modecode (get_mode_modecode)(const ir_mode *mode) { ANNOUNCE(); - return __get_mode_modecode(mode); + return _get_mode_modecode(mode); } ident * (get_mode_ident)(const ir_mode *mode) { ANNOUNCE(); - return __get_mode_ident(mode); + return _get_mode_ident(mode); } const char * @@ -382,27 +407,27 @@ mode_sort (get_mode_sort)(const ir_mode* mode) { ANNOUNCE(); - return __get_mode_sort(mode); + return _get_mode_sort(mode); } int (get_mode_size_bits)(const ir_mode *mode) { ANNOUNCE(); - return __get_mode_size_bits(mode); + return _get_mode_size_bits(mode); } int (get_mode_size_bytes)(const ir_mode *mode) { ANNOUNCE(); - return __get_mode_size_bytes(mode); + return _get_mode_size_bytes(mode); } int (get_mode_sign)(const ir_mode *mode) { ANNOUNCE(); - return __get_mode_sign(mode); + return _get_mode_sign(mode); } int @@ -419,25 +444,25 @@ int */ unsigned int (get_mode_modulo_shift)(const ir_mode *mode) { - return __get_mode_modulo_shift(mode); + return _get_mode_modulo_shift(mode); } unsigned int (get_mode_n_vector_elems)(const ir_mode *mode) { - return __get_mode_vector_elems(mode); + return _get_mode_vector_elems(mode); } void * (get_mode_link)(const ir_mode *mode) { ANNOUNCE(); - return __get_mode_link(mode); + return _get_mode_link(mode); } void (set_mode_link)(ir_mode *mode, void *l) { - __set_mode_link(mode, l); + _set_mode_link(mode, l); } tarval * @@ -484,6 +509,17 @@ get_mode_one (ir_mode *mode) return mode->one; } +tarval * +get_mode_minus_one (ir_mode *mode) +{ + ANNOUNCE(); + assert(mode); + assert(get_mode_modecode(mode) < num_modes); + assert(mode_is_data(mode)); + + return mode->minus_one; +} + tarval * get_mode_infinite(ir_mode *mode) { @@ -517,73 +553,73 @@ is_mode (void *thing) { int (mode_is_signed)(const ir_mode *mode) { ANNOUNCE(); - return __mode_is_signed(mode); + return _mode_is_signed(mode); } int (mode_is_float)(const ir_mode *mode) { ANNOUNCE(); - return __mode_is_float(mode); + return _mode_is_float(mode); } int (mode_is_int)(const ir_mode *mode) { ANNOUNCE(); - return __mode_is_int(mode); + return _mode_is_int(mode); } int (mode_is_character)(const ir_mode *mode) { ANNOUNCE(); - return __mode_is_character(mode); + return _mode_is_character(mode); } int (mode_is_reference)(const ir_mode *mode) { ANNOUNCE(); - return __mode_is_reference(mode); + return _mode_is_reference(mode); } int (mode_is_num)(const ir_mode *mode) { ANNOUNCE(); - return __mode_is_num(mode); + return _mode_is_num(mode); } int (mode_is_numP)(const ir_mode *mode) { ANNOUNCE(); - return __mode_is_numP(mode); + return _mode_is_numP(mode); } int (mode_is_data)(const ir_mode *mode) { ANNOUNCE(); - return __mode_is_data(mode); + return _mode_is_data(mode); } int (mode_is_datab)(const ir_mode *mode) { ANNOUNCE(); - return __mode_is_datab(mode); + return _mode_is_datab(mode); } int (mode_is_dataM)(const ir_mode *mode) { ANNOUNCE(); - return __mode_is_dataM(mode); + return _mode_is_dataM(mode); } int (mode_is_float_vector)(const ir_mode *mode) { ANNOUNCE(); - return __mode_is_float_vector(mode); + return _mode_is_float_vector(mode); } int (mode_is_int_vector)(const ir_mode *mode) { ANNOUNCE(); - return __mode_is_int_vector(mode); + return _mode_is_int_vector(mode); } /* Returns true if sm can be converted to lm without loss. */ @@ -848,14 +884,14 @@ init_mode (void) /* Character Modes */ newmode.sort = irms_character; - newmode.arithmetic = irma_none; + newmode.arithmetic = irma_twos_complement; + newmode.modulo_shift = 0; /* Character */ newmode.name = new_id_from_chars("C", 1); newmode.code = irm_C; newmode.sign = 0; newmode.size = 8; - newmode.modulo_shift = 32; mode_C = register_mode(&newmode); @@ -864,7 +900,6 @@ init_mode (void) newmode.code = irm_U; newmode.sign = 0; newmode.size = 16; - newmode.modulo_shift = 32; mode_U = register_mode(&newmode); @@ -881,8 +916,9 @@ init_mode (void) mode_P = register_mode(&newmode); - /* set the machine specific modes to the predifined ones */ - mode_P_mach = mode_P; + /* set the machine specific modes to the predefined ones */ + mode_P_code = mode_P; + mode_P_data = mode_P; } /* find a signed mode for an unsigned integer mode */ @@ -913,33 +949,72 @@ ir_mode *find_double_bits_int_mode(const ir_mode *mode) { return find_mode(&n); } +/* + * Returns non-zero if the given mode honors signed zero's, i.e., + * a +0 and a -0 exists and handled differently. + */ +int mode_honor_signed_zeros(const ir_mode *mode) +{ + /* for floating point, we know that IEEE 754 has +0 and -0, + * but always handles it identical. + */ + if (mode->sort == irms_float_number) + return mode->arithmetic == irma_ieee754 ? 0 : 1; + return 0; +} + +/* + * Returns non-zero if the given mode might overflow on unary Minus. + * + * This does NOT happen on IEEE 754. + */ +int mode_overflow_on_unary_Minus(const ir_mode *mode) +{ + if (mode->sort == irms_float_number) + return mode->arithmetic == irma_ieee754 ? 0 : 1; + return 1; +} + +/* + * Returns non-zero if the mode has a reversed wrap-aound + * logic, especially (a + x) - x == a. + * + * This is normally true for integer modes, not for floating + * point modes. + */ +int mode_wrap_around(const ir_mode *mode) { + /* FIXME: better would be an extra mode property */ + return mode_is_int(mode); +} + void finish_mode(void) { obstack_free(&modes, 0); - mode_T = NULL; - mode_X = NULL; - mode_M = NULL; - mode_BB = NULL; + mode_T = NULL; + mode_X = NULL; + mode_M = NULL; + mode_BB = NULL; mode_ANY = NULL; mode_BAD = NULL; - mode_F = NULL; - mode_D = NULL; - mode_E = NULL; - - mode_Bs = NULL; - mode_Bu = NULL; - mode_Hs = NULL; - mode_Hu = NULL; - mode_Is = NULL; - mode_Iu = NULL; - mode_Ls = NULL; - mode_Lu = NULL; - - mode_C = NULL; - mode_U = NULL; - mode_b = NULL; - mode_P = NULL; - - mode_P_mach = NULL; + mode_F = NULL; + mode_D = NULL; + mode_E = NULL; + + mode_Bs = NULL; + mode_Bu = NULL; + mode_Hs = NULL; + mode_Hu = NULL; + mode_Is = NULL; + mode_Iu = NULL; + mode_Ls = NULL; + mode_Lu = NULL; + + mode_C = NULL; + mode_U = NULL; + mode_b = NULL; + mode_P = NULL; + + mode_P_code = NULL; + mode_P_data = NULL; }