X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firmode.c;h=49c14ac13804881a01f05395b15f9302aacbbc74;hb=202b43933e0cc0b71cc7fbe2b092b94efb7fd30e;hp=8b57031f286108713266b256aae8e50fc682c6bc;hpb=32a00bce8f2e7dda0c17db9aacc16108263c23c5;p=libfirm diff --git a/ir/ir/irmode.c b/ir/ir/irmode.c index 8b57031f2..49c14ac13 100644 --- a/ir/ir/irmode.c +++ b/ir/ir/irmode.c @@ -23,27 +23,22 @@ * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Mathias Heil * @version $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "config.h" -#ifdef HAVE_STDLIB_H -# include -#endif -#ifdef HAVE_STRING_H -# include -#endif +#include +#include -# include +#include -# include "irprog_t.h" -# include "irmode_t.h" -# include "ident.h" -# include "tv_t.h" -# include "obst.h" -# include "irhooks.h" -# include "irtools.h" -# include "array.h" +#include "irprog_t.h" +#include "irmode_t.h" +#include "ident.h" +#include "tv_t.h" +#include "obst.h" +#include "irhooks.h" +#include "irtools.h" +#include "array.h" +#include "error.h" /** Obstack to hold all modes. */ static struct obstack modes; @@ -54,13 +49,29 @@ static int num_modes = 0; /** The list of all currently existing modes. */ static ir_mode **mode_list; +const char *get_mode_arithmetic_name(ir_mode_arithmetic ari) +{ +#define X(a) case a: return #a + switch (ari) { + X(irma_uninitialized); + X(irma_none); + X(irma_twos_complement); + X(irma_ones_complement); + X(irma_int_BCD); + X(irma_ieee754); + X(irma_float_BCD); + default: return ""; + } +#undef X +} + /** * Compare modes that don't need to have their code field * correctly set * * TODO: Add other fields **/ -static INLINE 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 && @@ -292,14 +303,15 @@ ir_mode *new_ir_mode(const char *name, ir_mode_sort sort, int bit_size, int sign case irms_control_flow: case irms_memory: case irms_internal_boolean: - assert(0 && "internal modes cannot be user defined"); - break; + panic("internal modes cannot be user defined"); case irms_float_number: case irms_int_number: case irms_reference: mode = register_mode(&mode_tmpl); + break; } + assert(mode != NULL); return mode; } @@ -339,20 +351,18 @@ ir_mode *new_ir_vector_mode(const char *name, ir_mode_sort sort, int bit_size, u case irms_control_flow: case irms_memory: case irms_internal_boolean: - assert(0 && "internal modes cannot be user defined"); - break; + panic("internal modes cannot be user defined"); case irms_reference: - assert(0 && "only integer and floating point modes can be vectorized"); - break; + panic("only integer and floating point modes can be vectorized"); case irms_float_number: - assert(0 && "not yet implemented"); - break; + panic("not yet implemented"); case irms_int_number: mode = register_mode(&mode_tmpl); } + assert(mode != NULL); return mode; } @@ -473,11 +483,8 @@ tarval *get_mode_NAN(ir_mode *mode) { return get_tarval_nan(mode); } -int is_mode(void *thing) { - if (get_kind(thing) == k_ir_mode) - return 1; - else - return 0; +int is_mode(const void *thing) { + return get_kind(thing) == k_ir_mode; } int (mode_is_signed)(const ir_mode *mode) { @@ -578,7 +585,7 @@ int smaller_mode(const ir_mode *sm, const ir_mode *lm) { break; case irms_reference: - /* do exist machines out there with different pointer lenghts ?*/ + /* do exist machines out there with different pointer lengths ?*/ return 0; case irms_internal_boolean: @@ -592,6 +599,37 @@ int smaller_mode(const ir_mode *sm, const ir_mode *lm) { return 0; } +/* Returns true if a value of mode sm can be converted into mode lm + and backwards without loss. */ +int values_in_mode(const ir_mode *sm, const ir_mode *lm) { + int sm_bits, lm_bits; + ir_mode_arithmetic arith; + + assert(sm); + assert(lm); + + if (sm == lm) return 1; + + if (sm == mode_b) + return mode_is_int(lm); + + sm_bits = get_mode_size_bits(sm); + lm_bits = get_mode_size_bits(lm); + + arith = get_mode_arithmetic(sm); + if (arith != get_mode_arithmetic(lm)) + return 0; + + switch (arith) { + case irma_twos_complement: + case irma_ieee754: + return get_mode_size_bits(sm) <= get_mode_size_bits(lm); + + default: + return 0; + } +} + /* Return the signed integer equivalent mode for an reference mode. */ ir_mode *get_reference_mode_signed_eq(ir_mode *mode) { assert(mode_is_reference(mode)); @@ -720,7 +758,9 @@ void init_mode(void) { newmode.name = new_id_from_chars("E", 1); newmode.code = irm_E; newmode.sign = 1; - newmode.size = 80; + /* note that the tarval module is calculating with 80 bits, but we use + * 96 bits, as that is what will be stored to memory by most hardware */ + newmode.size = 96; mode_E = register_mode(&newmode); @@ -843,7 +883,11 @@ void init_mode(void) { ir_mode *find_unsigned_mode(const ir_mode *mode) { ir_mode n = *mode; - assert(mode->sort == irms_int_number); + /* allowed for reference mode */ + if (mode->sort == irms_reference) + n.sort = irms_int_number; + + assert(n.sort == irms_int_number); n.sign = 0; return find_mode(&n); } @@ -903,6 +947,25 @@ int mode_wrap_around(const ir_mode *mode) { return mode_is_int(mode); } +/* + * Returns non-zero if the cast from mode src to mode dst is a + * reinterpret cast (ie. only the bit pattern is reinterpreted, + * no conversion is done) + */ +int is_reinterpret_cast(const ir_mode *src, const ir_mode *dst) { + ir_mode_arithmetic ma; + + if (src == dst) + return 1; + if (get_mode_size_bits(src) != get_mode_size_bits(dst)) + return 0; + ma = get_mode_arithmetic(src); + if (ma != get_mode_arithmetic(dst)) + return 0; + + return ma == irma_twos_complement || ma == irma_ones_complement; +} + void finish_mode(void) { obstack_free(&modes, 0); DEL_ARR_F(mode_list);