-/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-** All rights reserved.
-**
-** Authors: Martin Trapp, Christian Schaefer
-**
-*/
+/*
+ * Project: libFIRM
+ * File name: ir/ir/irmode.c
+ * Purpose: Data modes of operations.
+ * Author: Martin Trapp, Christian Schaefer
+ * Modified by: Goetz Lindenmaier, Mathias Heil
+ * Created:
+ * CVS-ID: $Id$
+ * Copyright: (c) 1998-2003 Universität Karlsruhe
+ * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
+ */
-/* $Id$ */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
-# include "irmode_t.h"
-# include "ident.h"
-# include <malloc.h>
+# include <stdlib.h>
# include <stddef.h>
# include <string.h>
+# include <stdbool.h>
+
+# include "irmode_t.h"
+# include "ident.h"
# include "tv.h"
-# include "array.h"
+# include "obst.h"
#if 0
static long long count = 0;
* * */
-/* dynamic array to hold all modes */
-static ir_mode * modes;
-/* dynamic arrays to hold special modes' values */
-static tarval** modes_min;
-static tarval** modes_max;
-static tarval** modes_null;
-static tarval** modes_one;
+/** dynamic array to hold all modes */
+static struct obstack modes;
-/* number of defined modes */
+/** number of defined modes */
static int num_modes;
/* * *
* local functions
* * */
-/* compare modes that don't need to have their code field
- * correctly set */
-static int modes_are_equal(ir_mode *m, ir_mode *n)
+/**
+ * Compare modes that don't need to have their code field
+ * correctly set
+ *
+ * TODO: Add other fields
+ **/
+INLINE static int modes_are_equal(const ir_mode *m, const ir_mode *n)
{
if (m == n) return 1;
- if ( (m->sort == n->sort) && (m->size == n->size) &&
- (m->align == n->align) && (m->sign == n->sign) &&
- (m->name == n->name) )
+ if (m->sort == n->sort &&
+ m->arithmetic == n->arithmetic &&
+ m->size == n->size &&
+ m->align == n->align &&
+ m->sign == n->sign &&
+ m->modulo_shift == n->modulo_shift &&
+ m->vector_elem == n->vector_elem)
return 1;
return 0;
}
-/* searches the modes array for the given mode and returns
+/*
+ * 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(ir_mode *m)
+ * none found
+ */
+static ir_mode *find_mode(const ir_mode *m)
{
- int i;
+ 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));
+ if (modes_are_equal(n, m))
+ return n;
+
+ n = nn;
+ nn = next_obstack_adr(&modes, n, sizeof(*n));
+ }
- for (i = 0; i < num_modes; i++)
- {
- if (modes_are_equal(m, &modes[i])) return &modes[i];
+ 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));
+ }
}
return NULL;
}
-/* sets special values of modes */
+/**
+ * sets special values of modes
+ */
static void set_mode_values(ir_mode* mode)
{
- modes_min[get_mode_modecode(mode)] = get_tarval_min(mode);
- modes_max[get_mode_modecode(mode)] = get_tarval_max(mode);
- modes_null[get_mode_modecode(mode)] = get_tarval_null(mode);
- modes_one[get_mode_modecode(mode)] = get_tarval_one(mode);
+ switch (get_mode_sort(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->null = get_tarval_null(mode);
+ mode->one = get_tarval_one(mode);
+ break;
+
+ case irms_internal_boolean:
+ mode->min = tarval_b_false;
+ mode->max = tarval_b_true;
+ mode->null = tarval_b_false;
+ mode->one = tarval_b_true;
+ 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;
+ break;
+
+ case irms_auxiliary:
+ case irms_memory:
+ case irms_control_flow:
+ mode->min = tarval_bad;
+ mode->max = tarval_bad;
+ mode->null = tarval_bad;
+ mode->one = tarval_bad;
+ break;
+ }
}
+
/* * *
* globals defined in irmode.h
* * */
-/** Predefined modes **/
+/* --- Predefined modes --- */
/* FIRM internal modes: */
ir_mode *mode_T;
ir_mode *mode_X;
ir_mode *mode_M;
ir_mode *mode_BB;
+ir_mode *mode_ANY;
+ir_mode *mode_BAD;
/* predefined numerical modes: */
ir_mode *mode_F; /* float */
ir_mode *mode_b;
ir_mode *mode_P;
+/* machine specific modes */
+ir_mode *mode_P_mach; /* machine specific pointer mode */
+
/* * *
* functions defined in irmode.h
* * */
/* JNI access functions */
-INLINE ir_mode *get_modeT() { ANNOUNCE(); return mode_T; }
-INLINE ir_mode *get_modeF() { ANNOUNCE(); return mode_F; }
-INLINE ir_mode *get_modeD() { ANNOUNCE(); return mode_D; }
-INLINE ir_mode *get_modeE() { ANNOUNCE(); return mode_E; }
-INLINE ir_mode *get_modeBs() { ANNOUNCE(); return mode_Bs; }
-INLINE ir_mode *get_modeBu() { ANNOUNCE(); return mode_Bu; }
-INLINE ir_mode *get_modeHs() { ANNOUNCE(); return mode_Hs; }
-INLINE ir_mode *get_modeHu() { ANNOUNCE(); return mode_Hu; }
-INLINE ir_mode *get_modeIs() { ANNOUNCE(); return mode_Is; }
-INLINE ir_mode *get_modeIu() { ANNOUNCE(); return mode_Iu; }
-INLINE ir_mode *get_modeLs() { ANNOUNCE(); return mode_Ls; }
-INLINE ir_mode *get_modeLu() { ANNOUNCE(); return mode_Lu; }
-INLINE ir_mode *get_modeC() { ANNOUNCE(); return mode_C; }
-INLINE ir_mode *get_modeU() { ANNOUNCE(); return mode_U; }
-INLINE ir_mode *get_modeb() { ANNOUNCE(); return mode_b; }
-INLINE ir_mode *get_modeP() { ANNOUNCE(); return mode_P; }
-INLINE ir_mode *get_modeX() { ANNOUNCE(); return mode_X; }
-INLINE ir_mode *get_modeM() { ANNOUNCE(); return mode_M; }
-INLINE ir_mode *get_modeBB() { ANNOUNCE(); return mode_BB; }
-
-/* ** Constructor ** */
-ir_mode *
-register_mode(ir_mode* new_mode)
+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_modeP_mach)(void) {
+ ANNOUNCE();
+ return __get_modeP_mach();
+}
+
+void (set_modeP_mach)(ir_mode *p) {
+ ANNOUNCE();
+ __set_modeP_mach(p);
+}
+
+/**
+ * Registers a new mode.
+ *
+ * @param new_mode The new mode template.
+ */
+static ir_mode *register_mode(const ir_mode* new_mode)
{
- ir_mode *mode;
+ ir_mode *mode = NULL;
ANNOUNCE();
assert(new_mode);
- /* first check if there already is a matching mode */
- mode = find_mode(new_mode);
- if (mode) return mode;
+ /* copy mode struct to modes array */
+ mode = (ir_mode*)obstack_copy(&modes, new_mode, sizeof(ir_mode));
+
+ mode->kind = k_ir_mode;
+ if (num_modes >= irm_max) mode->code = num_modes;
+ num_modes++;
+
+ set_mode_values(mode);
+
+ return mode;
+}
+
+/*
+ * Creates a new mode.
+ */
+ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int bit_align, int sign,
+ mode_arithmetic arithmetic, unsigned int modulo_shift )
+{
+ ir_mode mode_tmpl;
+ ir_mode *mode;
+
+ mode_tmpl.name = new_id_from_str(name);
+ mode_tmpl.sort = sort;
+ mode_tmpl.size = bit_size;
+ mode_tmpl.align = bit_align;
+ mode_tmpl.sign = sign ? 1 : 0;
+ mode_tmpl.modulo_shift = (mode_tmpl.sort == irms_int_number) ? modulo_shift : 0;
+ mode_tmpl.vector_elem = 1;
+ mode_tmpl.arithmetic = arithmetic;
+ mode_tmpl.link = NULL;
+ mode_tmpl.tv_priv = NULL;
+
+ mode = find_mode(&mode_tmpl);
+ if (mode)
+ {
+ return mode;
+ }
/* sanity checks */
- switch (new_mode->sort)
+ switch (sort)
{
- case auxiliary:
- case internal_boolean:
+ case irms_auxiliary:
+ case irms_control_flow:
+ case irms_memory:
+ case irms_internal_boolean:
assert(0 && "internal modes cannot be user defined");
- break;
+ return NULL;
- case float_number:
- assert(0 && "not yet implemented");
- break;
+ case irms_float_number:
+ case irms_int_number:
+ case irms_reference:
+ case irms_character:
+ return register_mode(&mode_tmpl);
+ }
+ return NULL; /* to shut up gcc */
+}
- case int_number:
- case reference:
- case character:
- break;
+/*
+ * Creates a new vector mode.
+ */
+ir_mode *new_ir_vector_mode(const char *name, mode_sort sort, int bit_size, unsigned num_of_elem, int bit_align, int sign,
+ mode_arithmetic arithmetic, unsigned int modulo_shift )
+{
+ ir_mode mode_tmpl;
+ ir_mode *mode;
- default:
- assert(0);
+ mode_tmpl.name = new_id_from_str(name);
+ mode_tmpl.sort = sort;
+ mode_tmpl.size = bit_size * num_of_elem;
+ mode_tmpl.align = bit_align;
+ mode_tmpl.sign = sign ? 1 : 0;
+ mode_tmpl.modulo_shift = (mode_tmpl.sort == irms_int_number) ? modulo_shift : 0;
+ mode_tmpl.vector_elem = num_of_elem;
+ mode_tmpl.arithmetic = arithmetic;
+ mode_tmpl.link = NULL;
+ mode_tmpl.tv_priv = NULL;
+
+ mode = find_mode(&mode_tmpl);
+ if (mode)
+ return mode;
+
+ if (num_of_elem <= 1) {
+ assert(0 && "vector modes should have at least 2 elements");
+ return NULL;
}
- /* copy mode struct to modes array */
- ARR_EXTEND(ir_mode, modes, 1);
- ARR_EXTEND(tarval*, modes_min, 1);
- ARR_EXTEND(tarval*, modes_max, 1);
- ARR_EXTEND(tarval*, modes_null, 1);
- ARR_EXTEND(tarval*, modes_one, 1);
- mode = &modes[num_modes];
-
- memcpy(mode, new_mode, sizeof(ir_mode));
- mode->code = num_modes;
- num_modes++;
+ /* sanity checks */
+ switch (sort)
+ {
+ case irms_auxiliary:
+ case irms_control_flow:
+ case irms_memory:
+ case irms_internal_boolean:
+ assert(0 && "internal modes cannot be user defined");
+ return NULL;
- set_mode_values(mode);
+ case irms_reference:
+ case irms_character:
+ assert(0 && "only integer and floating point modes can be vectorized");
+ return NULL;
- return mode;
+ case irms_float_number:
+ assert(0 && "not yet implemented");
+ return NULL;
+
+ case irms_int_number:
+ return register_mode(&mode_tmpl);
+ }
+ return NULL; /* to shut up gcc */
}
/* Functions for the direct access to all attributes od a ir_mode */
-#ifdef MODE_ACCESS_DEFINES
-# undef get_mode_modecode
-# undef get_mode_ident
-# undef get_mode_name
-# undef get_mode_sort
-# undef get_mode_size_bits
-# undef get_mode_align
-#endif
modecode
-get_mode_modecode(ir_mode *mode)
+(get_mode_modecode)(const ir_mode *mode)
{
ANNOUNCE();
- return mode->code;
+ return __get_mode_modecode(mode);
}
ident *
-get_mode_ident(ir_mode *mode)
+(get_mode_ident)(const ir_mode *mode)
{
ANNOUNCE();
- return mode->name;
+ return __get_mode_ident(mode);
}
const char *
-get_mode_name(ir_mode *mode)
+get_mode_name(const ir_mode *mode)
{
ANNOUNCE();
- return id_to_str(mode->name);
+ return get_id_str(mode->name);
}
mode_sort
-get_mode_sort(ir_mode* mode)
+(get_mode_sort)(const ir_mode* mode)
+{
+ ANNOUNCE();
+ return __get_mode_sort(mode);
+}
+
+int
+(get_mode_size_bits)(const ir_mode *mode)
{
ANNOUNCE();
- return mode->sort;
+ return __get_mode_size_bits(mode);
}
-INLINE int
-get_mode_size_bits(ir_mode *mode)
+int
+(get_mode_size_bytes)(const ir_mode *mode) {
+ ANNOUNCE();
+ return __get_mode_size_bytes(mode);
+}
+
+int
+(get_mode_align_bits)(const ir_mode *mode)
{
ANNOUNCE();
- return mode->size;
+ return __get_mode_align_bits(mode);
}
-int get_mode_size_bytes(ir_mode *mode) {
+int
+(get_mode_align_bytes)(const ir_mode *mode)
+{
ANNOUNCE();
- int size = get_mode_size_bits(mode);
- if ((size % 8) != 0) return -1;
- return size / 8;
+ return __get_mode_align_bytes(mode);
}
int
-get_mode_align (ir_mode *mode)
+(get_mode_sign)(const ir_mode *mode)
{
ANNOUNCE();
- return mode->align;
+ return __get_mode_sign(mode);
}
-#ifdef MODE_ACCESS_DEFINES
-# define get_mode_modecode(mode) (mode)->code
-# define get_mode_ident(mode) (mode)->name
-# define get_mode_name(mode) id_to_str((mode)->name)
-# define get_mode_sort(mode) (mode)->sort
-# define get_mode_size_bits(mode) (mode)->size
-# define get_mode_align(mode) (mode)->align
-#endif
+
int
-get_mode_sign (ir_mode *mode)
+(get_mode_arithmetic)(const ir_mode *mode)
{
ANNOUNCE();
- return mode->sign;
+ return get_mode_arithmetic(mode);
+}
+
+
+/* Attribute modulo shift specifies for modes of kind irms_int_number
+ * whether shift applies modulo to value of bits to shift. Asserts
+ * if mode is not irms_int_number.
+ */
+unsigned int
+(get_mode_modulo_shift)(const ir_mode *mode) {
+ return __get_mode_modulo_shift(mode);
+}
+
+unsigned int
+(get_mode_n_vector_elems)(const ir_mode *mode) {
+ return __get_mode_vector_elems(mode);
+}
+
+void *
+(get_mode_link)(const ir_mode *mode)
+{
+ ANNOUNCE();
+ return __get_mode_link(mode);
+}
+
+void
+(set_mode_link)(ir_mode *mode, void *l)
+{
+ __set_mode_link(mode, l);
}
tarval *
assert(get_mode_modecode(mode) < num_modes);
assert(mode_is_data(mode));
- return modes_min[get_mode_modecode(mode)];
+ return mode->min;
}
tarval *
assert(get_mode_modecode(mode) < num_modes);
assert(mode_is_data(mode));
- return modes_max[get_mode_modecode(mode)];
+ return mode->max;
}
tarval *
assert(get_mode_modecode(mode) < num_modes);
assert(mode_is_data(mode));
- return modes_null[get_mode_modecode(mode)];
+ return mode->null;
}
tarval *
assert(get_mode_modecode(mode) < num_modes);
assert(mode_is_data(mode));
- return modes_one[get_mode_modecode(mode)];
+ return mode->one;
}
tarval *
return get_tarval_nan(mode);
}
-/* Functions to check, whether a modecode is signed, float, int, num, data,
- datab or dataM. For more exact definitions read the corresponding pages
- in the firm documentation or the followingenumeration
-
- The set of "float" is defined as:
- ---------------------------------
- float = {irm_F, irm_D, irm_E}
-
- The set of "int" is defined as:
- -------------------------------
- int = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
-
- The set of "num" is defined as:
- -------------------------------
- num = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
- irm_Is, irm_Iu, irm_Ls, irm_Lu}
- = {float || int}
-
- The set of "data" is defined as:
- -------------------------------
- data = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
- irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
- = {num || irm_C || irm_U || irm_P}
-
- The set of "datab" is defined as:
- ---------------------------------
- datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
- irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
- = {data || irm_b }
-
- The set of "dataM" is defined as:
- ---------------------------------
- dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
- irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
- = {data || irm_M}
-*/
-
-#ifdef MODE_ACCESS_DEFINES
-# undef mode_is_signed
-# undef mode_is_float
-# undef mode_is_int
-# undef mode_is_num
-# undef mode_is_data
-# undef mode_is_datab
-# undef mode_is_dataM
-#endif
int
-mode_is_signed (ir_mode *mode)
-{
+is_mode (void *thing) {
+ if (get_kind(thing) == k_ir_mode)
+ return 1;
+ else
+ return 0;
+}
+
+int
+(mode_is_signed)(const ir_mode *mode) {
ANNOUNCE();
- assert(mode);
- return mode->sign;
+ return __mode_is_signed(mode);
}
int
-mode_is_float (ir_mode *mode)
-{
+(mode_is_float)(const ir_mode *mode) {
ANNOUNCE();
- assert(mode);
- return (get_mode_sort(mode) == float_number);
+ return __mode_is_float(mode);
}
int
-mode_is_int (ir_mode *mode)
-{
+(mode_is_int)(const ir_mode *mode) {
ANNOUNCE();
- assert(mode);
- return (get_mode_sort(mode) == int_number);
+ return __mode_is_int(mode);
}
int
-mode_is_num (ir_mode *mode)
-{
+(mode_is_character)(const ir_mode *mode) {
ANNOUNCE();
- assert(mode);
- return (mode_is_int(mode) || mode_is_float(mode));
+ return __mode_is_character(mode);
}
int
-mode_is_data (ir_mode *mode)
-{
+(mode_is_reference)(const ir_mode *mode) {
ANNOUNCE();
- assert(mode);
- return (mode_is_num(mode) || get_mode_sort(mode) == character || get_mode_sort(mode) == reference);
+ return __mode_is_reference(mode);
}
int
-mode_is_datab (ir_mode *mode)
-{
+(mode_is_num)(const ir_mode *mode) {
ANNOUNCE();
- assert(mode);
- return (mode_is_data(mode) || get_mode_sort(mode) == internal_boolean);
+ return __mode_is_num(mode);
}
int
-mode_is_dataM (ir_mode *mode)
-{
+(mode_is_numP)(const ir_mode *mode) {
ANNOUNCE();
- assert(mode);
- return (mode_is_data(mode) || get_mode_modecode(mode) == irm_M);
-}
-#ifdef MODE_ACCESS_DEFINES
-# define mode_is_signed(mode) (mode)->sign
-# define mode_is_float(mode) ((mode)->sort == float_number)
-# define mode_is_int(mode) ((mode)->sort == int_number)
-# define mode_is_num(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number))
-# define mode_is_data(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number) || ((mode)->sort == character) || ((mode)->sort == reference))
-# define mode_is_datab(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number) || ((mode)->sort == character) || ((mode)->sort == reference) || ((mode)->sort == internal_boolean))
-# define mode_is_dataM(mode) (((mode)->sort == float_number) || ((mode)->sort == int_number) || ((mode)->sort == character) || ((mode)->sort == reference) || ((mode)->code == irm_M))
-#endif
+ return __mode_is_numP(mode);
+}
+
+int
+(mode_is_data)(const ir_mode *mode) {
+ ANNOUNCE();
+ return __mode_is_data(mode);
+}
+
+int
+(mode_is_datab)(const ir_mode *mode) {
+ ANNOUNCE();
+ return __mode_is_datab(mode);
+}
+
+int
+(mode_is_dataM)(const ir_mode *mode) {
+ ANNOUNCE();
+ return __mode_is_dataM(mode);
+}
+
+int
+(mode_is_float_vector)(const ir_mode *mode) {
+ ANNOUNCE();
+ return __mode_is_float_vector(mode);
+}
+
+int
+(mode_is_int_vector)(const ir_mode *mode) {
+ ANNOUNCE();
+ return __mode_is_int_vector(mode);
+}
+
/* Returns true if sm can be converted to lm without loss. */
int
-smaller_mode(ir_mode *sm, ir_mode *lm)
+smaller_mode(const ir_mode *sm, const ir_mode *lm)
{
+ int sm_bits, lm_bits;
+
ANNOUNCE();
assert(sm);
assert(lm);
if (sm == lm) return 1;
+ sm_bits = get_mode_size_bits(sm);
+ lm_bits = get_mode_size_bits(lm);
+
switch(get_mode_sort(sm))
{
- case int_number:
+ case irms_int_number:
switch(get_mode_sort(lm))
{
- case int_number:
+ case irms_int_number:
/* integers are convertable if
* - both have the same sign and lm is the larger one
* - lm is the signed one and is at least two bits larger
* (one for the sign, one for the highest bit of sm)
+ * - sm & lm are two_complement and lm has greater or equal number of bits
*/
- if (mode_is_signed(sm))
+ if ( get_mode_arithmetic(sm) == get_mode_arithmetic(lm)
+ && get_mode_arithmetic(sm) == irma_twos_complement) {
+ return lm_bits >= sm_bits;
+ }
+ else if (mode_is_signed(sm))
{
- if ( mode_is_signed(lm) && (get_mode_size_bits(lm) > get_mode_size_bits(sm)) )
+ if ( mode_is_signed(lm) && (lm_bits >= sm_bits) )
return 1;
}
else if (mode_is_signed(lm))
{
- if (get_mode_size_bits(lm) > get_mode_size_bits(sm) + 1)
+ if (lm_bits > sm_bits + 1)
return 1;
}
- else if (get_mode_size_bits(lm) > get_mode_size_bits(sm))
+ else if (lm_bits >= sm_bits)
{
return 1;
}
break;
- case float_number:
+ case irms_float_number:
/* int to float works if the float is large enough */
return 0;
}
break;
- case float_number:
- /* XXX currently only the three standard 32,64,80 bit floats
- * are supported which can safely be converted */
- if ( (get_mode_sort(lm) == float_number)
- && (get_mode_size_bits(lm) > get_mode_size_bits(sm)) )
- return 1;
+ case irms_float_number:
+ if (get_mode_arithmetic(sm) == get_mode_arithmetic(lm)) {
+ if ( (get_mode_sort(lm) == irms_float_number)
+ && (get_mode_size_bits(lm) >= get_mode_size_bits(sm)) )
+ return 1;
+ }
break;
- case reference:
+ case irms_reference:
/* do exist machines out there with different pointer lenghts ?*/
return 0;
return 0;
}
-/** ** initialization ** **/
+/* initialization, build the default modes */
void
init_mode (void)
{
+ ir_mode newmode;
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);
+ obstack_init(&modes);
+
+ num_modes = 0;
/* initialize predefined modes */
+
+ /* Internal Modes */
+ newmode.arithmetic = irma_none;
+ newmode.size = 0;
+ newmode.align = 0;
+ newmode.sign = 0;
+ newmode.modulo_shift = 0;
+ newmode.vector_elem = 0;
+ newmode.link = NULL;
+ newmode.tv_priv = NULL;
+
+ /* Control Flow Modes*/
+ newmode.sort = irms_control_flow;
+
/* Basic Block */
- mode_BB = &modes[irm_BB];
- mode_BB->name = id_from_str("BB", 2);
- mode_BB->code = irm_BB;
- mode_BB->sort = auxiliary;
- mode_BB->sign = 0;
-
- /* eXecution */
- mode_X = &modes[irm_X];
- mode_X->name = id_from_str("X", 1);
- mode_X->code = irm_X;
- mode_X->sort = auxiliary;
- mode_X->sign = 0;
+ 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 */
- mode_M = &modes[irm_M];
- mode_M->name = id_from_str("M", 1);
- mode_M->code = irm_M;
- mode_M->sort = auxiliary;
- mode_M->sign = 0;
+ newmode.name = new_id_from_chars("M", 1);
+ newmode.code = irm_M;
+
+ mode_M = register_mode(&newmode);
+
+ /* Auxiliary Modes */
+ newmode.sort = irms_auxiliary,
/* Tuple */
- mode_T = &modes[irm_T];
- mode_T->name = id_from_str("T", 1);
- mode_T->code = irm_T;
- mode_T->sign = 0;
+ 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 */
- mode_b = &modes[irm_b];
- mode_b->name = id_from_str("b", 1);
- mode_b->code = irm_b;
- mode_b->sort = internal_boolean;
- mode_b->sign = 0;
+ 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 */
- mode_F = &modes[irm_F];
- mode_F->name = id_from_str("F", 1);
- mode_F->code = irm_F;
- mode_F->sort = float_number;
- mode_F->sign = 1;
- mode_F->align = 32;
- mode_F->size = 32;
+ newmode.name = new_id_from_chars("F", 1);
+ newmode.code = irm_F;
+ newmode.sign = 1;
+ newmode.align = 32;
+ newmode.size = 32;
- set_mode_values(mode_F);
+ mode_F = register_mode(&newmode);
/* double */
- mode_D = &modes[irm_D];
- mode_D->name = id_from_str("D", 1);
- mode_D->code = irm_D;
- mode_D->sort = float_number;
- mode_D->sign = 1;
- mode_D->align = 32;
- mode_D->size = 64;
+ newmode.name = new_id_from_chars("D", 1);
+ newmode.code = irm_D;
+ newmode.sign = 1;
+ newmode.align = 64;
+ newmode.size = 64;
- set_mode_values(mode_D);
+ mode_D = register_mode(&newmode);
/* extended */
- mode_E = &modes[irm_E];
- mode_E->name = id_from_str("E", 1);
- mode_E->code = irm_E;
- mode_E->sort = float_number;
- mode_E->sign = 1;
- mode_E->align = 32;
- mode_E->size = 80;
+ newmode.name = new_id_from_chars("E", 1);
+ newmode.code = irm_E;
+ newmode.sign = 1;
+ newmode.align = 128;
+ newmode.size = 80;
+
+ mode_E = register_mode(&newmode);
- set_mode_values(mode_E);
+ /* Integer Number Modes */
+ newmode.sort = irms_int_number;
+ newmode.arithmetic = irma_twos_complement;
/* signed byte */
- mode_Bs = &modes[irm_Bs];
- mode_Bs->name = id_from_str("Bs", 2);
- mode_Bs->code = irm_Bs;
- mode_Bs->sort = int_number;
- mode_Bs->sign = 1;
- mode_Bs->align = 8;
- mode_Bs->size = 8;
+ newmode.name = new_id_from_chars("Bs", 2);
+ newmode.code = irm_Bs;
+ newmode.sign = 1;
+ newmode.align = 8;
+ newmode.size = 8;
+ newmode.modulo_shift = 32;
- set_mode_values(mode_Bs);
+ mode_Bs = register_mode(&newmode);
/* unsigned byte */
- mode_Bu = &modes[irm_Bu];
- mode_Bu->name = id_from_str("Bu", 2);
- mode_Bu->code = irm_Bu;
- mode_Bu->sort = int_number;
- mode_Bu->sign = 0;
- mode_Bu->align = 8;
- mode_Bu->size = 8;
+ newmode.name = new_id_from_chars("Bu", 2);
+ newmode.code = irm_Bu;
+ newmode.arithmetic = irma_twos_complement;
+ newmode.sign = 0;
+ newmode.align = 8;
+ newmode.size = 8;
+ newmode.modulo_shift = 32;
- set_mode_values(mode_Bu);
+ mode_Bu = register_mode(&newmode);
/* signed short integer */
- mode_Hs = &modes[irm_Hs];
- mode_Hs->name = id_from_str("Hs", 2);
- mode_Hs->code = irm_Hs;
- mode_Hs->sort = int_number;
- mode_Hs->sign = 1;
- mode_Hs->align = 16;
- mode_Hs->size = 16;
+ newmode.name = new_id_from_chars("Hs", 2);
+ newmode.code = irm_Hs;
+ newmode.sign = 1;
+ newmode.align = 16;
+ newmode.size = 16;
+ newmode.modulo_shift = 32;
- set_mode_values(mode_Hs);
+ mode_Hs = register_mode(&newmode);
/* unsigned short integer */
- mode_Hu = &modes[irm_Hu];
- mode_Hu->name = id_from_str("Hu", 2);
- mode_Hu->code = irm_Hu;
- mode_Hu->sort = int_number;
- mode_Hu->sign = 0;
- mode_Hu->align = 16;
- mode_Hu->size = 16;
+ newmode.name = new_id_from_chars("Hu", 2);
+ newmode.code = irm_Hu;
+ newmode.sign = 0;
+ newmode.align = 16;
+ newmode.size = 16;
+ newmode.modulo_shift = 32;
- set_mode_values(mode_Hu);
+ mode_Hu = register_mode(&newmode);
/* signed integer */
- mode_Is = &modes[irm_Is];
- mode_Is->name = id_from_str("Is", 2);
- mode_Is->code = irm_Is;
- mode_Is->sort = int_number;
- mode_Is->sign = 1;
- mode_Is->align = 32;
- mode_Is->size = 32;
+ newmode.name = new_id_from_chars("Is", 2);
+ newmode.code = irm_Is;
+ newmode.sign = 1;
+ newmode.align = 32;
+ newmode.size = 32;
+ newmode.modulo_shift = 32;
- set_mode_values(mode_Is);
+ mode_Is = register_mode(&newmode);
/* unsigned integer */
- mode_Iu = &modes[irm_Iu];
- mode_Iu->name = id_from_str("Iu", 2);
- mode_Iu->code = irm_Iu;
- mode_Iu->sort = int_number;
- mode_Iu->sign = 0;
- mode_Iu->align = 32;
- mode_Iu->size = 32;
+ newmode.name = new_id_from_chars("Iu", 2);
+ newmode.code = irm_Iu;
+ newmode.sign = 0;
+ newmode.align = 32;
+ newmode.size = 32;
+ newmode.modulo_shift = 32;
- set_mode_values(mode_Iu);
+ mode_Iu = register_mode(&newmode);
/* signed long integer */
- mode_Ls = &modes[irm_Ls];
- mode_Ls->name = id_from_str("Ls", 2);
- mode_Ls->code = irm_Ls;
- mode_Ls->sort = int_number;
- mode_Ls->sign = 1;
- mode_Ls->align = 32;
- mode_Ls->size = 64;
+ newmode.name = new_id_from_chars("Ls", 2);
+ newmode.code = irm_Ls;
+ newmode.sign = 1;
+ newmode.align = 32;
+ newmode.size = 64;
+ newmode.modulo_shift = 64;
- set_mode_values(mode_Ls);
+ mode_Ls = register_mode(&newmode);
/* unsigned long integer */
- mode_Lu = &modes[irm_Lu];
- mode_Lu->name = id_from_str("Lu", 2);
- mode_Lu->code = irm_Lu;
- mode_Lu->sort = int_number;
- mode_Lu->sign = 0;
- mode_Lu->align = 32;
- mode_Lu->size = 64;
+ newmode.name = new_id_from_chars("Lu", 2);
+ newmode.code = irm_Lu;
+ newmode.sign = 0;
+ newmode.align = 32;
+ newmode.size = 64;
+ newmode.modulo_shift = 64;
+
+ mode_Lu = register_mode(&newmode);
- set_mode_values(mode_Lu);
+ /* Character Modes */
+ newmode.sort = irms_character;
+ newmode.arithmetic = irma_none;
/* Character */
- mode_C = &modes[irm_C];
- mode_C->name = id_from_str("C", 1);
- mode_C->code = irm_C;
- mode_C->sort = character;
- mode_C->sign = 0;
- mode_C->align = 8;
- mode_C->size = 8;
+ newmode.name = new_id_from_chars("C", 1);
+ newmode.code = irm_C;
+ newmode.sign = 0;
+ newmode.align = 8;
+ newmode.size = 8;
+ newmode.modulo_shift = 32;
- set_mode_values(mode_C);
+ mode_C = register_mode(&newmode);
/* Unicode character */
- mode_U = &modes[irm_U];
- mode_U->name = id_from_str("U", 1);
- mode_U->code = irm_U;
- mode_U->sort = character;
- mode_U->sign = 0;
- mode_U->align = 16;
- mode_U->size = 16;
+ newmode.name = new_id_from_chars("U", 1);
+ newmode.code = irm_U;
+ newmode.sign = 0;
+ newmode.align = 16;
+ newmode.size = 16;
+ newmode.modulo_shift = 32;
- set_mode_values(mode_U);
+ mode_U = register_mode(&newmode);
+
+ /* Reference Modes */
+ newmode.sort = irms_reference;
+ newmode.arithmetic = irma_twos_complement;
/* pointer */
- mode_P = &modes[irm_P];
- mode_P->name = id_from_str("P", 1);
- mode_P->code = irm_P;
- mode_P->sort = reference;
- mode_P->sign = 0;
- mode_P->align = 32;
- mode_P->size = 32;
-
- num_modes = irm_max;
+ newmode.name = new_id_from_chars("P", 1);
+ newmode.code = irm_P;
+ newmode.sign = 0;
+ newmode.align = 32;
+ newmode.size = 32;
+ newmode.modulo_shift = 0;
+
+ mode_P = register_mode(&newmode);
+
+ /* set the machine specific modes to the predifined ones */
+ mode_P_mach = mode_P;
+}
+
+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);
+}
+
+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);
+}
+
+
+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_C = NULL;
+ mode_U = NULL;
+ mode_b = NULL;
+ mode_P = NULL;
+
+ mode_P_mach = NULL;
}