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.
32 #include "firm_types.h"
36 * Contains relevant information about a mode.
38 * Necessary information about a mode is stored in this struct
39 * which is used by the tarval module to perform calculations
40 * and comparisons of values of a such described mode.
43 * - modecode code: An unambiguous int (enum) for the mode
44 * - ident *name: Name of this mode. Two modes are different if the name is different.
45 * - mode_sort sort: sort of mode specifying possible usage categories
46 * - int size: size of the mode in Bits.
47 * - unsigned sign:1: signedness of this mode
49 * - modulo_shift specifies for modes of kind irms_int_number
50 * whether shift applies modulo to value of bits to shift
53 * The tech report 1999-44 describing FIRM and predefined modes
56 typedef struct ir_mode ir_mode;
58 /* ********** Predefined modes ********** */
61 * Predefined mode according to tech report 1999-14.
63 typedef enum { /* irm is short for `ir mode' */
64 irm_BB, /**< basic block */
65 irm_X, /**< execution */
66 irm_F, /**< float(32) */
67 irm_D, /**< double(64) */
68 irm_E, /**< extended(80) */
69 irm_Bs, /**< signed byte(8) */
70 irm_Bu, /**< unsigned byte(8) */
71 irm_Hs, /**< signed short(16) */
72 irm_Hu, /**< unsigned short(16) */
73 irm_Is, /**< signed int(32) */
74 irm_Iu, /**< unsigned int(32) */
75 irm_Ls, /**< signed long(64) */
76 irm_Lu, /**< unsigned long(64) */
77 irm_C, /**< character */
78 irm_P, /**< pointer */
79 irm_b, /**< internal boolean */
82 irm_U, /**< unicode character */
83 irm_ANY, /**< undefined mode */
84 irm_BAD, /**< bad mode */
85 irm_max /**< maximum value for modecode */
88 /** These values represent the different mode classes of value representations.
91 /* Predefined sorts of modes */
92 irms_auxiliary, /**< Only for Firm use. Not extensible. (irm_T) */
93 irms_control_flow, /**< Marks all control flow modes. Not extensible. (irm_BB, irm_X) */
94 irms_memory, /**< Marks the memory mode. Not extensible. (irm_M) */
95 irms_internal_boolean, /**< Internal boolean representation.
96 Storing to memory impossible, convert first. (irm_b) */
97 /** user-extensible sorts of modes **/
98 irms_int_number, /**< A mode to represent int numbers.
99 Integer computations can be performed. */
100 irms_float_number, /**< A mode to represent float numbers.
101 Floating point computations can be performed. */
102 irms_reference, /**< A mode to represent entities.
103 Restricted int computations can be performed */
104 irms_character /**< A mode to represent characters/symbols
105 ?? Are computations allowed? as int?? */
108 /** These values represent the different arithmetic operations possible with a mode.
109 Further arithmetics can be defined, e.g., for @@@ modes.
112 irma_uninitialized = 0,
113 irma_none = 1, /**< For modes for which no representation is specified.
114 These are modes of sort auxiliary, internal_boolean and
116 irma_twos_complement = 2, /**< Values of the mode are represented as two's complement.
117 Only legal for modes of sort int_number and reference. */
118 irma_ones_complement, /**< Values of the mode are represented as one's complement.
119 Only legal for modes of sort int_number and reference. */
120 irma_int_BCD, /**< Values of the mode are represented as binary coded decimals.
121 Only legal for modes of sort int_number and reference. */
122 irma_ieee754 = 256, /**< Values of the mode are represented according to ieee754
123 floatingpoint standard. Only legal for modes of sort float_number. */
124 irma_float_BCD, /**< Values of the mode are represented as binary coded decimals
125 according to @@@ which standards??? Only legal for modes of
126 sort float_number. */
131 /* ********** Constructor for user defined modes **************** */
133 * Creates a new mode.
135 * @param name the name of the mode to be created
136 * @param sort the mode_sort of the mode to be created
137 * @param bit_size number of bits this mode allocate
138 * @param sign non-zero if this is a signed mode
139 * @param arithmetic arithmetic operations possible with a mode
140 * @param modulo_shift Is ignored for modes other than integer.
142 * This function constructs a new mode given by the parameters.
143 * If the parameters match an already defined mode, this mode is returned
144 * (including the default modes).
145 * If the mode is newly allocated, a new unique mode_code is chosen.
146 * Also, special value tarvals will be calculated such as null,
147 * min, max and can be retrieved using the get_mode_* functions
150 * The new mode or NULL on error.
153 * It is allowed to construct the default modes. So, a call
154 * new_ir_mode("Is", irms_int_number, 32, 1, irma_twos_complement, 32) will return mode_Is.
156 ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int sign, mode_arithmetic arithmetic, unsigned int modulo_shift);
159 * Creates a new vector mode.
161 * @param name the name of the mode to be created
162 * @param sort the mode_sort of the mode to be created
163 * @param bit_size number of bits for one element of this mode
164 * @param num_of_elem number of elements in this vector mode
165 * @param sign non-zero if this is a signed mode
166 * @param arithmetic arithmetic operations possible with a mode
167 * @param modulo_shift Is ignored for modes other than integer.
169 * This function constructs a new vector mode given by the parameters.
170 * If the parameters match an already defined mode, this mode is returned.
171 * If the mode is newly allocated, a new unique mode_code is chosen.
172 * Also, special value tarvals will be calculated such as null,
173 * min, max and can be retrieved using the get_mode_* functions
176 * The new mode or NULL on error.
178 ir_mode *new_ir_vector_mode(const char *name, mode_sort sort, int bit_size, unsigned num_of_elem, int sign,
179 mode_arithmetic arithmetic, unsigned int modulo_shift );
182 * Checks whether a pointer points to a mode.
184 * @param thing an arbitrary pointer
187 * true if the thing is a mode, else false
189 int is_mode(void *thing);
191 /* ********** Access methods to read mode information *********** */
193 /** Returns the classification of the mode */
194 modecode get_mode_modecode(const ir_mode *mode);
196 /** Returns the ident* of the mode */
197 ident *get_mode_ident(const ir_mode *mode);
199 /** Returns the null-terminated name of this mode. */
200 const char *get_mode_name(const ir_mode *mode);
202 /** Returns a coarse classification of the mode. */
203 mode_sort get_mode_sort(const ir_mode *mode);
205 /** Returns the size of values of the mode in bits. */
206 int get_mode_size_bits(const ir_mode *mode);
208 /** Returns the size of values of the mode in bytes.
209 * If the size is not dividable by 8 returns -1. */
210 int get_mode_size_bytes(const ir_mode *mode);
212 /** Returns the signess of a mode.
214 * Returns the signess of a mode: 1 if mode is signed. */
215 int get_mode_sign(const ir_mode *mode);
217 /** Returns the arithmetic of a mode */
218 int get_mode_arithmetic(const ir_mode *mode);
220 /** Get the modulo shift attribute.
222 * Attribute modulo shift specifies for modes of kind irms_int_number
223 * whether shift applies modulo to value of bits to shift. Zero for
224 * modes that are not integer.
226 unsigned int get_mode_modulo_shift(const ir_mode *mode);
228 /** Return the number of vector elements.
230 * Attribute vector_elem specifies the number of vector elements of
231 * a vector mode. For non-vector modes it returns 1 for data and 0
232 * for all other modes
234 unsigned int get_mode_n_vector_elems(const ir_mode *mode);
236 /** Returns the stored intermediate information. */
237 void *get_mode_link(const ir_mode *mode);
239 /** Stores new intermediate information. */
240 void set_mode_link(ir_mode *mode, void *l);
243 * Returns the smallest representable value of a given mode.
245 * For modes of the sort float_number this is the most negative value
246 * bigger than -infinite.
248 tarval *get_mode_min(ir_mode *mode);
251 * Returns the biggest representable value o f a given mode.
253 * For modes of the sort float_number this is the largest value lower
256 tarval *get_mode_max(ir_mode *mode);
259 * Returns the value Zero represented in this mode.
261 * Zero is the additive neutral element and as such
262 * is defined only for modes allowing addition, i.e.
263 * op_pin_state_floats and ints, and references (NULL-Pointer)
264 * else returns tarval_bad.
266 tarval *get_mode_null(ir_mode *mode);
269 * Returns the value One, represented in this mode.
271 * One, being the multiplicative neutral element,
272 * is defined only for modes allowing multiplication,
273 * i.e. ints and floats.
275 tarval *get_mode_one(ir_mode *mode);
278 * Returns the value Minus One, represented in this mode.
280 * Minus One is defined only for modes allowing
281 * multiplication with signed values, i.e. signed ints and floats.
283 tarval *get_mode_minus_one(ir_mode *mode);
286 * Returns the positive infinite value of a mode.
288 * This is only valid for float_numbers, other modes
289 * will result in tarval_bad.
291 tarval *get_mode_infinite(ir_mode *mode);
294 * Returns the NAN value of a given mode.
296 * This is only valid for float_numbers, other modes
297 * will result in tarval_bad.
299 tarval *get_mode_NAN(ir_mode *mode);
301 extern ir_mode *mode_M; /**< memory */
303 /* -- A set of predefined, numerical modes according to Techreport 1999-44 -- */
304 extern ir_mode *mode_F; /**< signed float(32) */
305 extern ir_mode *mode_D; /**< signed double(64) */
306 extern ir_mode *mode_E; /**< signed extended(80) */
307 extern ir_mode *mode_Bs; /**< signed byte (former char) */
308 extern ir_mode *mode_Bu; /**< unsigned byte (former char) */
309 extern ir_mode *mode_Hs; /**< signed short integer */
310 extern ir_mode *mode_Hu; /**< unsigned short integer */
311 extern ir_mode *mode_Is; /**< signed integer */
312 extern ir_mode *mode_Iu; /**< unsigned integer */
313 extern ir_mode *mode_Ls; /**< signed long integer */
314 extern ir_mode *mode_Lu; /**< unsigned long integer */
316 extern ir_mode *mode_C; /**< 8 bit char */
317 extern ir_mode *mode_U; /**< 16 bit unicode char */
319 extern ir_mode *mode_P; /**< pointer */
320 extern ir_mode *mode_P_code; /**< A pointer mode that is set by the client of libfirm. This mode
321 represents the pointer size of the target machine code addresses. Is initialized
323 extern ir_mode *mode_P_data; /**< A pointer mode that is set by the client of libfirm. This mode
324 represents the pointer size of the target machine data addresses. Is initialized
327 /* -- Auxiliary modes necessary for the Firm representation -- */
328 extern ir_mode *mode_b; /**< internal boolean */
330 extern ir_mode *mode_X; /**< execution */
331 extern ir_mode *mode_BB; /**< block */
333 extern ir_mode *mode_T; /**< tuple (none) */
334 extern ir_mode *mode_ANY;/**< undefined mode */
335 extern ir_mode *mode_BAD;/**< bad mode */
338 /** Access routines for JNI Interface */
339 ir_mode *get_modeF(void);
340 ir_mode *get_modeD(void);
341 ir_mode *get_modeE(void);
342 ir_mode *get_modeBs(void);
343 ir_mode *get_modeBu(void);
344 ir_mode *get_modeHs(void);
345 ir_mode *get_modeHu(void);
346 ir_mode *get_modeIs(void);
347 ir_mode *get_modeIu(void);
348 ir_mode *get_modeLs(void);
349 ir_mode *get_modeLu(void);
350 ir_mode *get_modeC(void);
351 ir_mode *get_modeU(void);
352 ir_mode *get_modeP(void);
353 ir_mode *get_modeb(void);
354 ir_mode *get_modeX(void);
355 ir_mode *get_modeBB(void);
356 ir_mode *get_modeM(void);
357 ir_mode *get_modeT(void);
358 ir_mode *get_modeANY(void);
359 ir_mode *get_modeBAD(void);
361 /** Returns the machine specific pointer mode for code addresses. */
362 ir_mode *get_modeP_code(void);
364 /** Returns the machine specific pointer mode for data addresses. */
365 ir_mode *get_modeP_data(void);
368 * Sets the machine specific pointer mode for code addresses.
369 * If not set, the predefined mode mode_P will be used.
371 void set_modeP_code(ir_mode *p);
374 * Sets the machine specific pointer mode for data addresses.
375 * If not set, the predefined mode mode_P will be used.
377 void set_modeP_data(ir_mode *p);
380 Functions to check, whether a modecode is signed, float, int, character,
381 reference, num, numP, data, datab or dataM.
383 For more exact definitions read the corresponding pages
384 in the firm documentation or the following enumeration
386 The set of "float" is defined as:
387 float = {irm_F, irm_D, irm_E}
389 The set of "int" is defined as:
390 int = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
392 The set of "character" is defined as:
393 character = {irm_C, irm_U}
395 The set of "reference" is defined as:
398 The set of "num" is defined as:
401 The set of "numP" is defined as:
402 numP = {float || int || reference}
404 The set of "data" is defined as:
405 data = {num || character || reference}
407 The set of "datab" is defined as:
408 datab = {data || irm_b }
410 The set of "dataM" is defined as:
411 dataM = {data || irm_M}
413 Vector "int" and "float" are defined by the arithmetic and vector_elem > 1.
416 /* Test for a certain class of modes. */
417 int mode_is_signed (const ir_mode *mode);
418 int mode_is_float (const ir_mode *mode);
419 int mode_is_int (const ir_mode *mode);
420 int mode_is_character (const ir_mode *mode);
421 int mode_is_reference (const ir_mode *mode);
422 int mode_is_num (const ir_mode *mode);
423 int mode_is_numP (const ir_mode *mode);
424 int mode_is_data (const ir_mode *mode);
425 int mode_is_datab (const ir_mode *mode);
426 int mode_is_dataM (const ir_mode *mode);
427 int mode_is_float_vector (const ir_mode *mode);
428 int mode_is_int_vector (const ir_mode *mode);
430 /** Returns true if sm can be converted to lm without loss
431 according to firm definiton */
432 int smaller_mode(const ir_mode *sm, const ir_mode *lm);
435 * Returns a matching unsigned mode for a given integer signed mode.
436 * Returns NULL if no matching mode exists.
438 ir_mode *find_unsigned_mode(const ir_mode *mode);
441 * Returns a matching signed mode for a given integer unsigned mode.
442 * Returns NULL if no matching mode exists.
444 ir_mode *find_signed_mode(const ir_mode *mode);
447 * Returns an integer mode with 2*n bits for a given integer mode with n bits.
448 * Returns NULL if no matching mode exists.
450 ir_mode *find_double_bits_int_mode(const ir_mode *mode);
453 * Returns non-zero if the given mode honors signed zero's, i.e.,
454 * a +0 and a -0 exists and handled differently.
456 int mode_honor_signed_zeros(const ir_mode *mode);
459 * Returns non-zero if the given mode might overflow on unary Minus.
461 int mode_overflow_on_unary_Minus(const ir_mode *mode);
464 * Returns non-zero if the mode has a reversed wrap-aound
465 * logic, especially (a + x) - x == a.
466 * This is normally true for integer modes, not for floating
469 int mode_wrap_around(const ir_mode *mode);
471 #endif /* _IRMODE_H_ */