3 * File name: ir/ir/irmode.h
4 * Purpose: Data modes of operations.
5 * Author: Martin Trapp, Christian Schaefer
6 * Modified by: Goetz Lindenmaier, Mathias Heil
9 * Copyright: (c) 1998-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 * irmode -- Modes for ir operators
17 * @author Christian Schaefer, Matthias Heil
19 * This module specifies the modes that type the firm nodes. It defines
20 * a datasturcture that describes a mode and implements constructors and
21 * access routines to this datastructure. Further it defines a set of
25 * UKA tech report 1999-44 for more information about modes.
34 #ifndef _TARVAL_TYPEDEF_
35 #define _TARVAL_TYPEDEF_
36 typedef struct tarval tarval;
40 * Contains relevant information about a mode.
42 * Necessary information about a mode is stored in this struct
43 * which is used by the tarval module to perform calculations
44 * and comparisons of values of a such described mode.
47 * - modecode code: An unambiguous int (enum) for the mode
48 * - ident *name: Name of this mode. Two modes are different if the name is different.
49 * - mode_sort sort: sort of mode specifying possible usage categories
50 * - int size: size of the mode in Bits.
51 * - unsigned sign:1: signedness of this mode
53 * - modulo_shift specifies for modes of kind irms_int_number
54 * whether shift applies modulo to value of bits to shift
57 * The tech report 1999-44 describing FIRM and predefined modes
60 typedef struct ir_mode ir_mode;
62 /* ********** Predefined modes ********** */
65 * Predefined mode according to tech report 1999-14.
67 typedef enum { /* irm is short for `ir mode' */
68 irm_BB, /**< basic block */
69 irm_X, /**< execution */
70 irm_F, /**< float(32) */
71 irm_D, /**< double(64) */
72 irm_E, /**< extended(80) */
73 irm_Bs, /**< signed byte(8) */
74 irm_Bu, /**< unsigned byte(8) */
75 irm_Hs, /**< signed short(16) */
76 irm_Hu, /**< unsigned short(16) */
77 irm_Is, /**< signed int(32) */
78 irm_Iu, /**< unsigned int(32) */
79 irm_Ls, /**< signed long(64) */
80 irm_Lu, /**< unsigned long(64) */
81 irm_C, /**< character */
82 irm_P, /**< pointer */
83 irm_b, /**< internal boolean */
86 irm_U, /**< unicode character */
87 irm_ANY, /**< undefined mode */
88 irm_BAD, /**< bad mode */
89 irm_max /**< maximum value for modecode */
92 /** These values represent the different mode classes of value representations.
95 /* Predefined sorts of modes */
96 irms_auxiliary, /**< Only for Firm use. Not extensible. (irm_T) */
97 irms_control_flow, /**< Marks all control flow modes. Not extensible. (irm_BB, irm_X) */
98 irms_memory, /**< Marks the memory mode. Not extensible. (irm_M) */
99 irms_internal_boolean, /**< Internal boolean representation.
100 Storing to memory impossible, convert first. (irm_b) */
101 /** user-extensible sorts of modes **/
102 irms_int_number, /**< A mode to represent int numbers.
103 Integer computations can be performed. */
104 irms_float_number, /**< A mode to represent float numbers.
105 Floating point computations can be performed. */
106 irms_reference, /**< A mode to represent entities.
107 Restricted int computations can be performed */
108 irms_character /**< A mode to represent characters/symbols
109 ?? Are computations allowed? as int?? */
112 /** These values represent the different arithmetic operations possible with a mode.
113 Further arithmetics can be defined, e.g., for @@@ modes.
116 irma_uninitialized = 0,
117 irma_none = 1, /**< For modes for which no representation is specified.
118 These are modes of sort auxiliary, internal_boolean and
120 irma_twos_complement = 2, /**< Values of the mode are represented as two's complement.
121 Only legal for modes of sort int_number and reference. */
122 irma_ones_complement, /**< Values of the mode are represented as one's complement.
123 Only legal for modes of sort int_number and reference. */
124 irma_int_BCD, /**< Values of the mode are represented as binary coded decimals.
125 Only legal for modes of sort int_number and reference. */
126 irma_ieee754 = 256, /**< Values of the mode are represented according to ieee754
127 floatingpoint standard. Only legal for modes of sort float_number. */
128 irma_float_BCD, /**< Values of the mode are represented as binary coded decimals
129 according to @@@ which standards??? Only legal for modes of
130 sort float_number. */
135 /* ********** Constructor for user defined modes **************** */
137 * Creates a new mode.
139 * @param name the name of the mode to be created
140 * @param sort the mode_sort of the mode to be created
141 * @param bit_size number of bits this mode allocate
142 * @param sign non-zero if this is a signed mode
143 * @param arithmetic arithmetic operations possible with a mode
144 * @param modulo_shift Is ignored for modes other than integer.
146 * This function constructs a new mode given by the parameters.
147 * If the parameters match an already defined mode, this mode is returned
148 * (including the default modes).
149 * If the mode is newly allocated, a new unique mode_code is chosen.
150 * Also, special value tarvals will be calculated such as null,
151 * min, max and can be retrieved using the get_mode_* functions
154 * The new mode or NULL on error.
157 * It is allowed to construct the default modes. So, a call
158 * new_ir_mode("Is", irms_int_number, 32, 1, irma_twos_complement, 32) will return mode_Is.
160 ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int sign, mode_arithmetic arithmetic, unsigned int modulo_shift);
163 * Creates a new vector mode.
165 * @param name the name of the mode to be created
166 * @param sort the mode_sort of the mode to be created
167 * @param bit_size number of bits for one element of this mode
168 * @param num_of_elem number of elements in this vector mode
169 * @param sign non-zero if this is a signed mode
170 * @param arithmetic arithmetic operations possible with a mode
171 * @param modulo_shift Is ignored for modes other than integer.
173 * This function constructs a new vector mode given by the parameters.
174 * If the parameters match an already defined mode, this mode is returned.
175 * If the mode is newly allocated, a new unique mode_code is chosen.
176 * Also, special value tarvals will be calculated such as null,
177 * min, max and can be retrieved using the get_mode_* functions
180 * The new mode or NULL on error.
182 ir_mode *new_ir_vector_mode(const char *name, mode_sort sort, int bit_size, unsigned num_of_elem, int sign,
183 mode_arithmetic arithmetic, unsigned int modulo_shift );
186 * Checks whether a pointer points to a mode.
188 * @param thing an arbitrary pointer
191 * true if the thing is a mode, else false
193 int is_mode(void *thing);
195 /* ********** Access methods to read mode information *********** */
197 /** Returns the classification of the mode */
198 modecode get_mode_modecode(const ir_mode *mode);
200 /** Returns the ident* of the mode */
201 ident *get_mode_ident(const ir_mode *mode);
203 /** Returns the null-terminated name of this mode. */
204 const char *get_mode_name(const ir_mode *mode);
206 /** Returns a coarse classification of the mode. */
207 mode_sort get_mode_sort(const ir_mode *mode);
209 /** Returns the size of values of the mode in bits. */
210 int get_mode_size_bits(const ir_mode *mode);
212 /** Returns the size of values of the mode in bytes.
213 * If the size is not dividable by 8 returns -1. */
214 int get_mode_size_bytes(const ir_mode *mode);
216 /** Returns the signess of a mode.
218 * Returns the signess of a mode: 1 if mode is signed. */
219 int get_mode_sign(const ir_mode *mode);
221 /** Returns the arithmetic of a mode */
222 int get_mode_arithmetic(const ir_mode *mode);
224 /** Get the modulo shift attribute.
226 * Attribute modulo shift specifies for modes of kind irms_int_number
227 * whether shift applies modulo to value of bits to shift. Zero for
228 * modes that are not integer.
230 unsigned int get_mode_modulo_shift(const ir_mode *mode);
232 /** Return the number of vector elements.
234 * Attribute vector_elem specifies the number of vector elements of
235 * a vector mode. For non-vector modes it returns 1 for data and 0
236 * for all other modes
238 unsigned int get_mode_n_vector_elems(const ir_mode *mode);
240 /** Returns the stored intermediate information. */
241 void *get_mode_link(const ir_mode *mode);
243 /** Stores new intermediate information. */
244 void set_mode_link(ir_mode *mode, void *l);
247 * Returns the smallest representable value of a given mode.
249 * For modes of the sort float_number this is the most negative value
250 * bigger than -infinite.
252 tarval *get_mode_min(ir_mode *mode);
255 * Returns the biggest representable value o f a given mode.
257 * For modes of the sort float_number this is the largest value lower
260 tarval *get_mode_max(ir_mode *mode);
263 * Returns the value Zero represented in this mode.
265 * Zero is the additive neutral element and as such
266 * is defined only for modes allowing addition, i.e.
267 * op_pin_state_floats and ints, and references (NULL-Pointer)
268 * else returns tarval_bad.
270 tarval *get_mode_null(ir_mode *mode);
273 * Returns the value One, represented in this mode.
275 * One, being the multiplicative neutral element,
276 * is defined only for modes allowing multiplication,
277 * i.e. ints and floats.
279 tarval *get_mode_one(ir_mode *mode);
282 * Returns the value Minus One, represented in this mode.
284 * Minus One is defined only for modes allowing
285 * multiplication with signed values, i.e. signed ints and floats.
287 tarval *get_mode_minus_one(ir_mode *mode);
290 * Returns the positive infinite value of a mode.
292 * This is only valid for float_numbers, other modes
293 * will result in tarval_bad.
295 tarval *get_mode_infinite(ir_mode *mode);
298 * Returns the NAN value of a given mode.
300 * This is only valid for float_numbers, other modes
301 * will result in tarval_bad.
303 tarval *get_mode_NAN(ir_mode *mode);
305 extern ir_mode *mode_M; /**< memory */
307 /* -- A set of predefined, numerical modes according to Techreport 1999-44 -- */
308 extern ir_mode *mode_F; /**< signed float(32) */
309 extern ir_mode *mode_D; /**< signed double(64) */
310 extern ir_mode *mode_E; /**< signed extended(80) */
311 extern ir_mode *mode_Bs; /**< signed byte (former char) */
312 extern ir_mode *mode_Bu; /**< unsigned byte (former char) */
313 extern ir_mode *mode_Hs; /**< signed short integer */
314 extern ir_mode *mode_Hu; /**< unsigned short integer */
315 extern ir_mode *mode_Is; /**< signed integer */
316 extern ir_mode *mode_Iu; /**< unsigned integer */
317 extern ir_mode *mode_Ls; /**< signed long integer */
318 extern ir_mode *mode_Lu; /**< unsigned long integer */
320 extern ir_mode *mode_C; /**< 8 bit char */
321 extern ir_mode *mode_U; /**< 16 bit unicode char */
323 extern ir_mode *mode_P; /**< pointer */
324 extern ir_mode *mode_P_code; /**< A pointer mode that is set by the client of libfirm. This mode
325 represents the pointer size of the target machine code addresses. Is initialized
327 extern ir_mode *mode_P_data; /**< A pointer mode that is set by the client of libfirm. This mode
328 represents the pointer size of the target machine data addresses. Is initialized
331 /* -- Auxiliary modes necessary for the Firm representation -- */
332 extern ir_mode *mode_b; /**< internal boolean */
334 extern ir_mode *mode_X; /**< execution */
335 extern ir_mode *mode_BB; /**< block */
337 extern ir_mode *mode_T; /**< tuple (none) */
338 extern ir_mode *mode_ANY;/**< undefined mode */
339 extern ir_mode *mode_BAD;/**< bad mode */
342 /** Access routines for JNI Interface */
343 ir_mode *get_modeF(void);
344 ir_mode *get_modeD(void);
345 ir_mode *get_modeE(void);
346 ir_mode *get_modeBs(void);
347 ir_mode *get_modeBu(void);
348 ir_mode *get_modeHs(void);
349 ir_mode *get_modeHu(void);
350 ir_mode *get_modeIs(void);
351 ir_mode *get_modeIu(void);
352 ir_mode *get_modeLs(void);
353 ir_mode *get_modeLu(void);
354 ir_mode *get_modeC(void);
355 ir_mode *get_modeU(void);
356 ir_mode *get_modeP(void);
357 ir_mode *get_modeb(void);
358 ir_mode *get_modeX(void);
359 ir_mode *get_modeBB(void);
360 ir_mode *get_modeM(void);
361 ir_mode *get_modeT(void);
362 ir_mode *get_modeANY(void);
363 ir_mode *get_modeBAD(void);
365 /** Returns the machine specific pointer mode for code addresses. */
366 ir_mode *get_modeP_code(void);
368 /** Returns the machine specific pointer mode for data addresses. */
369 ir_mode *get_modeP_data(void);
372 * Sets the machine specific pointer mode for code addresses.
373 * If not set, the predefined mode mode_P will be used.
375 void set_modeP_code(ir_mode *p);
378 * Sets the machine specific pointer mode for data addresses.
379 * If not set, the predefined mode mode_P will be used.
381 void set_modeP_data(ir_mode *p);
384 Functions to check, whether a modecode is signed, float, int, character,
385 reference, num, numP, data, datab or dataM.
387 For more exact definitions read the corresponding pages
388 in the firm documentation or the following enumeration
390 The set of "float" is defined as:
391 float = {irm_F, irm_D, irm_E}
393 The set of "int" is defined as:
394 int = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
396 The set of "character" is defined as:
397 character = {irm_C, irm_U}
399 The set of "reference" is defined as:
402 The set of "num" is defined as:
405 The set of "numP" is defined as:
406 numP = {float || int || reference}
408 The set of "data" is defined as:
409 data = {num || character || reference}
411 The set of "datab" is defined as:
412 datab = {data || irm_b }
414 The set of "dataM" is defined as:
415 dataM = {data || irm_M}
417 Vector "int" and "float" are defined by the arithmetic and vector_elem > 1.
420 /* Test for a certain class of modes. */
421 int mode_is_signed (const ir_mode *mode);
422 int mode_is_float (const ir_mode *mode);
423 int mode_is_int (const ir_mode *mode);
424 int mode_is_character (const ir_mode *mode);
425 int mode_is_reference (const ir_mode *mode);
426 int mode_is_num (const ir_mode *mode);
427 int mode_is_numP (const ir_mode *mode);
428 int mode_is_data (const ir_mode *mode);
429 int mode_is_datab (const ir_mode *mode);
430 int mode_is_dataM (const ir_mode *mode);
431 int mode_is_float_vector (const ir_mode *mode);
432 int mode_is_int_vector (const ir_mode *mode);
434 /** Returns true if sm can be converted to lm without loss
435 according to firm definiton */
436 int smaller_mode(const ir_mode *sm, const ir_mode *lm);
439 * Returns a matching unsigned mode for a given integer signed mode.
440 * Returns NULL if no matching mode exists.
442 ir_mode *find_unsigned_mode(const ir_mode *mode);
445 * Returns a matching signed mode for a given integer unsigned mode.
446 * Returns NULL if no matching mode exists.
448 ir_mode *find_signed_mode(const ir_mode *mode);
451 * Returns an integer mode with 2*n bits for a given integer mode with n bits.
452 * Returns NULL if no matching mode exists.
454 ir_mode *find_double_bits_int_mode(const ir_mode *mode);
457 * Returns non-zero if the given mode honors signed zero's, i.e.,
458 * a +0 and a -0 exists and handled differently.
460 int mode_honor_signed_zeros(const ir_mode *mode);
463 * Returns non-zero if the given mode might overflow on unary Minus.
465 int mode_overflow_on_unary_Minus(const ir_mode *mode);
468 * Returns non-zero if the mode has a reversed wrap-aound
469 * logic, especially (a + x) - x == a.
470 * This is normally true for integer modes, not for floating
473 int mode_wrap_around(const ir_mode *mode);
475 #endif /* _IRMODE_H_ */