-init_mode (void)
-{
- ANNOUNCE();
- /* init flexible array */
- modes = NEW_ARR_F(ir_mode, irm_max);
- modes_min = NEW_ARR_F(tarval*, irm_max);
- modes_max = NEW_ARR_F(tarval*, irm_max);
- modes_null = NEW_ARR_F(tarval*, irm_max);
- modes_one = NEW_ARR_F(tarval*, irm_max);
-
- /* initialize predefined modes */
- /* Basic Block */
- mode_BB = &modes[irm_BB];
- mode_BB->name = id_from_str("BB", 2);
- mode_BB->code = irm_BB;
- mode_BB->sort = irms_auxiliary;
- mode_BB->size = 0;
- mode_BB->align = 0;
- mode_BB->sign = 0;
- mode_BB->tv_priv = NULL;
-
- /* eXecution */
- mode_X = &modes[irm_X];
- mode_X->name = id_from_str("X", 1);
- mode_X->code = irm_X;
- mode_X->sort = irms_auxiliary;
- mode_X->size = 0;
- mode_X->align = 0;
- mode_X->sign = 0;
- mode_X->tv_priv = NULL;
-
- /* Memory */
- mode_M = &modes[irm_M];
- mode_M->name = id_from_str("M", 1);
- mode_M->code = irm_M;
- mode_M->sort = irms_auxiliary;
- mode_M->size = 0;
- mode_M->align = 0;
- mode_M->sign = 0;
- mode_M->tv_priv = NULL;
-
- /* Tuple */
- mode_T = &modes[irm_T];
- mode_T->name = id_from_str("T", 1);
- mode_T->code = irm_T;
- mode_T->sort = irms_auxiliary,
- mode_T->size = 0;
- mode_T->align = 0;
- mode_T->sign = 0;
- mode_T->tv_priv = NULL;
-
- /* ANY */
- mode_ANY = &modes[irm_ANY];
- mode_ANY->name = id_from_str("ANY", 3);
- mode_ANY->code = irm_ANY;
- mode_ANY->sort = irms_auxiliary;
- mode_ANY->sign = 0;
- mode_ANY->align = 0;
- mode_ANY->size = 0;
- mode_ANY->tv_priv = NULL;
-
- /* BAD */
- mode_BAD = &modes[irm_BAD];
- mode_BAD->name = id_from_str("BAD", 3);
- mode_BAD->code = irm_BAD;
- mode_BAD->sort = irms_auxiliary;
- mode_BAD->sign = 0;
- mode_BAD->align = 0;
- mode_BAD->size = 0;
- mode_BAD->tv_priv = NULL;
-
- /* boolean */
- mode_b = &modes[irm_b];
- mode_b->name = id_from_str("b", 1);
- mode_b->code = irm_b;
- mode_b->sort = irms_internal_boolean;
- mode_b->size = 0;
- mode_b->align = 0;
- mode_b->sign = 0;
- mode_b->tv_priv = NULL;
-
- /* float */
- mode_F = &modes[irm_F];
- mode_F->name = id_from_str("F", 1);
- mode_F->code = irm_F;
- mode_F->sort = irms_float_number;
- mode_F->sign = 1;
- mode_F->align = 4;
- mode_F->size = 32;
- mode_F->tv_priv = NULL;
-
- set_mode_values(mode_F);
-
- /* double */
- mode_D = &modes[irm_D];
- mode_D->name = id_from_str("D", 1);
- mode_D->code = irm_D;
- mode_D->sort = irms_float_number;
- mode_D->sign = 1;
- mode_D->align = 4;
- mode_D->size = 64;
- mode_D->tv_priv = NULL;
-
- set_mode_values(mode_D);
-
- /* extended */
- mode_E = &modes[irm_E];
- mode_E->name = id_from_str("E", 1);
- mode_E->code = irm_E;
- mode_E->sort = irms_float_number;
- mode_E->sign = 1;
- mode_E->align = 4;
- mode_E->size = 80;
- mode_E->tv_priv = NULL;
-
- set_mode_values(mode_E);
-
- /* signed byte */
- mode_Bs = &modes[irm_Bs];
- mode_Bs->name = id_from_str("Bs", 2);
- mode_Bs->code = irm_Bs;
- mode_Bs->sort = irms_int_number;
- mode_Bs->sign = 1;
- mode_Bs->align = 1;
- mode_Bs->size = 8;
- mode_Bs->tv_priv = NULL;
-
- set_mode_values(mode_Bs);
-
- /* unsigned byte */
- mode_Bu = &modes[irm_Bu];
- mode_Bu->name = id_from_str("Bu", 2);
- mode_Bu->code = irm_Bu;
- mode_Bu->sort = irms_int_number;
- mode_Bu->sign = 0;
- mode_Bu->align = 1;
- mode_Bu->size = 8;
- mode_Bu->tv_priv = NULL;
-
- set_mode_values(mode_Bu);
-
- /* signed short integer */
- mode_Hs = &modes[irm_Hs];
- mode_Hs->name = id_from_str("Hs", 2);
- mode_Hs->code = irm_Hs;
- mode_Hs->sort = irms_int_number;
- mode_Hs->sign = 1;
- mode_Hs->align = 2;
- mode_Hs->size = 16;
- mode_Hs->tv_priv = NULL;
-
- set_mode_values(mode_Hs);
-
- /* unsigned short integer */
- mode_Hu = &modes[irm_Hu];
- mode_Hu->name = id_from_str("Hu", 2);
- mode_Hu->code = irm_Hu;
- mode_Hu->sort = irms_int_number;
- mode_Hu->sign = 0;
- mode_Hu->align = 2;
- mode_Hu->size = 16;
- mode_Hu->tv_priv = NULL;
-
- set_mode_values(mode_Hu);
-
- /* signed integer */
- mode_Is = &modes[irm_Is];
- mode_Is->name = id_from_str("Is", 2);
- mode_Is->code = irm_Is;
- mode_Is->sort = irms_int_number;
- mode_Is->sign = 1;
- mode_Is->align = 4;
- mode_Is->size = 32;
- mode_Is->tv_priv = NULL;
-
- set_mode_values(mode_Is);
-
- /* unsigned integer */
- mode_Iu = &modes[irm_Iu];
- mode_Iu->name = id_from_str("Iu", 2);
- mode_Iu->code = irm_Iu;
- mode_Iu->sort = irms_int_number;
- mode_Iu->sign = 0;
- mode_Iu->align = 4;
- mode_Iu->size = 32;
- mode_Iu->tv_priv = NULL;
-
- set_mode_values(mode_Iu);
-
- /* signed long integer */
- mode_Ls = &modes[irm_Ls];
- mode_Ls->name = id_from_str("Ls", 2);
- mode_Ls->code = irm_Ls;
- mode_Ls->sort = irms_int_number;
- mode_Ls->sign = 1;
- mode_Ls->align = 4;
- mode_Ls->size = 64;
- mode_Ls->tv_priv = NULL;
-
- set_mode_values(mode_Ls);
-
- /* unsigned long integer */
- mode_Lu = &modes[irm_Lu];
- mode_Lu->name = id_from_str("Lu", 2);
- mode_Lu->code = irm_Lu;
- mode_Lu->sort = irms_int_number;
- mode_Lu->sign = 0;
- mode_Lu->align = 4;
- mode_Lu->size = 64;
- mode_Lu->tv_priv = NULL;
-
- set_mode_values(mode_Lu);
-
- /* Character */
- mode_C = &modes[irm_C];
- mode_C->name = id_from_str("C", 1);
- mode_C->code = irm_C;
- mode_C->sort = irms_character;
- mode_C->sign = 0;
- mode_C->align = 1;
- mode_C->size = 8;
- mode_C->tv_priv = NULL;
-
- set_mode_values(mode_C);
-
- /* Unicode character */
- mode_U = &modes[irm_U];
- mode_U->name = id_from_str("U", 1);
- mode_U->code = irm_U;
- mode_U->sort = irms_character;
- mode_U->sign = 0;
- mode_U->align = 2;
- mode_U->size = 16;
- mode_U->tv_priv = NULL;
-
- set_mode_values(mode_U);
-
- /* pointer */
- mode_P = &modes[irm_P];
- mode_P->name = id_from_str("P", 1);
- mode_P->code = irm_P;
- mode_P->sort = irms_reference;
- mode_P->sign = 0;
- mode_P->align = 4;
- mode_P->size = 32;
- mode_P->tv_priv = NULL;
-
- num_modes = irm_max;
+init_mode(void) {
+ ir_mode newmode;
+
+ obstack_init(&modes);
+
+ num_modes = 0;
+ /* initialize predefined modes */
+
+ /* Internal Modes */
+ newmode.arithmetic = irma_none;
+ newmode.size = 0;
+ newmode.sign = 0;
+ newmode.modulo_shift = 0;
+ newmode.vector_elem = 0;
+ newmode.eq_signed = NULL;
+ newmode.eq_unsigned = NULL;
+ newmode.link = NULL;
+ newmode.tv_priv = NULL;
+
+ /* Control Flow Modes*/
+ newmode.sort = irms_control_flow;
+
+ /* Basic Block */
+ newmode.name = new_id_from_chars("BB", 2);
+ newmode.code = irm_BB;
+
+ mode_BB = register_mode(&newmode);
+
+ /* eXecution */
+ newmode.name = new_id_from_chars("X", 1);
+ newmode.code = irm_X;
+
+ mode_X = register_mode(&newmode);
+
+ /* Memory Modes */
+ newmode.sort = irms_memory;
+
+ /* Memory */
+ newmode.name = new_id_from_chars("M", 1);
+ newmode.code = irm_M;
+
+ mode_M = register_mode(&newmode);
+
+ /* Auxiliary Modes */
+ newmode.sort = irms_auxiliary,
+
+ /* Tuple */
+ newmode.name = new_id_from_chars("T", 1);
+ newmode.code = irm_T;
+
+ mode_T = register_mode(&newmode);
+
+ /* ANY */
+ newmode.name = new_id_from_chars("ANY", 3);
+ newmode.code = irm_ANY;
+
+ mode_ANY = register_mode(&newmode);
+
+ /* BAD */
+ newmode.name = new_id_from_chars("BAD", 3);
+ newmode.code = irm_BAD;
+
+ mode_BAD = register_mode(&newmode);
+
+ /* Internal Boolean Modes */
+ newmode.sort = irms_internal_boolean;
+
+ /* boolean */
+ newmode.name = new_id_from_chars("b", 1);
+ newmode.code = irm_b;
+
+ mode_b = register_mode(&newmode);
+
+ /* Data Modes */
+ newmode.vector_elem = 1;
+
+ /* Float Number Modes */
+ newmode.sort = irms_float_number;
+ newmode.arithmetic = irma_ieee754;
+
+ /* float */
+ newmode.name = new_id_from_chars("F", 1);
+ newmode.code = irm_F;
+ newmode.sign = 1;
+ newmode.size = 32;
+
+ mode_F = register_mode(&newmode);
+
+ /* double */
+ newmode.name = new_id_from_chars("D", 1);
+ newmode.code = irm_D;
+ newmode.sign = 1;
+ newmode.size = 64;
+
+ mode_D = register_mode(&newmode);
+
+ /* extended */
+ newmode.name = new_id_from_chars("E", 1);
+ newmode.code = irm_E;
+ newmode.sign = 1;
+ newmode.size = 80;
+
+ mode_E = register_mode(&newmode);
+
+ /* Integer Number Modes */
+ newmode.sort = irms_int_number;
+ newmode.arithmetic = irma_twos_complement;
+
+ /* signed byte */
+ newmode.name = new_id_from_chars("Bs", 2);
+ newmode.code = irm_Bs;
+ newmode.sign = 1;
+ newmode.size = 8;
+ newmode.modulo_shift = 32;
+
+ mode_Bs = register_mode(&newmode);
+
+ /* unsigned byte */
+ newmode.name = new_id_from_chars("Bu", 2);
+ newmode.code = irm_Bu;
+ newmode.arithmetic = irma_twos_complement;
+ newmode.sign = 0;
+ newmode.size = 8;
+ newmode.modulo_shift = 32;
+
+ mode_Bu = register_mode(&newmode);
+
+ /* signed short integer */
+ newmode.name = new_id_from_chars("Hs", 2);
+ newmode.code = irm_Hs;
+ newmode.sign = 1;
+ newmode.size = 16;
+ newmode.modulo_shift = 32;
+
+ mode_Hs = register_mode(&newmode);
+
+ /* unsigned short integer */
+ newmode.name = new_id_from_chars("Hu", 2);
+ newmode.code = irm_Hu;
+ newmode.sign = 0;
+ newmode.size = 16;
+ newmode.modulo_shift = 32;
+
+ mode_Hu = register_mode(&newmode);
+
+ /* signed integer */
+ newmode.name = new_id_from_chars("Is", 2);
+ newmode.code = irm_Is;
+ newmode.sign = 1;
+ newmode.size = 32;
+ newmode.modulo_shift = 32;
+
+ mode_Is = register_mode(&newmode);
+
+ /* unsigned integer */
+ newmode.name = new_id_from_chars("Iu", 2);
+ newmode.code = irm_Iu;
+ newmode.sign = 0;
+ newmode.size = 32;
+ newmode.modulo_shift = 32;
+
+ mode_Iu = register_mode(&newmode);
+
+ /* signed long integer */
+ newmode.name = new_id_from_chars("Ls", 2);
+ newmode.code = irm_Ls;
+ newmode.sign = 1;
+ newmode.size = 64;
+ newmode.modulo_shift = 64;
+
+ mode_Ls = register_mode(&newmode);
+
+ /* unsigned long integer */
+ newmode.name = new_id_from_chars("Lu", 2);
+ newmode.code = irm_Lu;
+ newmode.sign = 0;
+ newmode.size = 64;
+ newmode.modulo_shift = 64;
+
+ mode_Lu = register_mode(&newmode);
+
+ /* signed long long integer */
+ newmode.name = new_id_from_chars("LLs", 3);
+ newmode.code = irm_LLs;
+ newmode.sign = 1;
+ newmode.size = 128;
+ newmode.modulo_shift = 128;
+
+ mode_LLs = register_mode(&newmode);
+
+ /* unsigned long long integer */
+ newmode.name = new_id_from_chars("LLu", 3);
+ newmode.code = irm_LLu;
+ newmode.sign = 0;
+ newmode.size = 128;
+ newmode.modulo_shift = 128;
+
+ mode_LLu = register_mode(&newmode);
+
+ /* Reference Mode */
+ newmode.sort = irms_reference;
+ newmode.arithmetic = irma_twos_complement;
+
+ /* pointer */
+ newmode.name = new_id_from_chars("P", 1);
+ newmode.code = irm_P;
+ newmode.sign = 0;
+ newmode.size = 32;
+ newmode.modulo_shift = 0;
+ newmode.eq_signed = mode_Is;
+ newmode.eq_unsigned = mode_Iu;
+
+ mode_P = register_mode(&newmode);
+
+ /* 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 */
+ir_mode *find_unsigned_mode(const ir_mode *mode) {
+ ir_mode n = *mode;
+
+ assert(mode->sort == irms_int_number);
+ n.sign = 0;
+ return find_mode(&n);
+}
+
+/* find an unsigned mode for a signed integer mode */
+ir_mode *find_signed_mode(const ir_mode *mode) {
+ ir_mode n = *mode;
+
+ assert(mode->sort == irms_int_number);
+ n.sign = 1;
+ return find_mode(&n);
+}
+
+/* finds a integer mode with 2*n bits for an integer mode with n bits. */
+ir_mode *find_double_bits_int_mode(const ir_mode *mode) {
+ ir_mode n = *mode;
+
+ assert(mode->sort == irms_int_number && mode->arithmetic == irma_twos_complement);
+
+ n.size = 2*mode->size;
+ 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.
+ */
+ return
+ mode->sort == irms_float_number &&
+ mode->arithmetic != irma_ieee754;
+}
+
+/*
+ * 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-around
+ * 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_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_b = NULL;
+
+ mode_P = NULL;
+ mode_P_code = NULL;
+ mode_P_data = NULL;