2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Data modes of operations.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Mathias Heil,
27 * This module specifies the modes that type the firm nodes. It defines
28 * a datasturcture that describes a mode and implements constructors and
29 * access routines to this datastructure. Further it defines a set of
33 * UKA tech report 1999-44 for more information about modes.
35 #ifndef FIRM_IR_IRMODE_H
36 #define FIRM_IR_IRMODE_H
38 #include "firm_types.h"
41 /* ********** Predefined modes ********** */
44 * Predefined mode according to tech report 1999-14.
46 typedef enum { /* irm is short for `ir mode' */
47 irm_BB, /**< basic block */
48 irm_X, /**< execution */
49 irm_F, /**< float(32) */
50 irm_D, /**< double(64) */
51 irm_E, /**< extended(80) */
52 irm_Bs, /**< signed byte(8) */
53 irm_Bu, /**< unsigned byte(8) */
54 irm_Hs, /**< signed short(16) */
55 irm_Hu, /**< unsigned short(16) */
56 irm_Is, /**< signed int(32) */
57 irm_Iu, /**< unsigned int(32) */
58 irm_Ls, /**< signed long(64) */
59 irm_Lu, /**< unsigned long(64) */
60 irm_LLs, /**< signed long long(128) */
61 irm_LLu, /**< unsigned long long(128) */
62 irm_C, /**< character */
63 irm_P, /**< pointer */
64 irm_b, /**< internal boolean */
67 irm_U, /**< unicode character */
68 irm_ANY, /**< undefined mode */
69 irm_BAD, /**< bad mode */
70 irm_max /**< maximum value for modecode */
73 /** These values represent the different mode classes of value representations.
76 /* Predefined sorts of modes */
77 irms_auxiliary, /**< Only for Firm use. Not extensible. (irm_T) */
78 irms_control_flow, /**< Marks all control flow modes. Not extensible. (irm_BB, irm_X) */
79 irms_memory, /**< Marks the memory mode. Not extensible. (irm_M) */
80 irms_internal_boolean, /**< Internal boolean representation.
81 Storing to memory impossible, convert first. (irm_b) */
82 /* user-extensible sorts of modes */
83 irms_int_number, /**< A mode to represent int numbers.
84 Integer computations can be performed. */
85 irms_float_number, /**< A mode to represent float numbers.
86 Floating point computations can be performed. */
87 irms_reference, /**< A mode to represent entities.
88 Restricted int computations can be performed */
91 /** These values represent the different arithmetic operations possible with a mode.
92 Further arithmetics can be defined, e.g., for @@@ modes.
95 irma_uninitialized = 0,
96 irma_none = 1, /**< For modes for which no representation is specified.
97 These are modes of sort auxiliary, internal_boolean and character. */
98 irma_twos_complement = 2, /**< Values of the mode are represented as two's complement.
99 Only legal for modes of sort int_number and reference. */
100 irma_ones_complement, /**< Values of the mode are represented as one's complement.
101 Only legal for modes of sort int_number and reference. */
102 irma_int_BCD, /**< Values of the mode are represented as binary coded decimals.
103 Only legal for modes of sort int_number and reference. */
104 irma_ieee754 = 256, /**< Values of the mode are represented according to ieee754
105 floating point standard. Only legal for modes of sort float_number. */
106 irma_float_BCD, /**< Values of the mode are represented as binary coded decimals
107 according to @@@ which standards??? Only legal for modes of
108 sort float_number. */
113 /* ********** Constructor for user defined modes **************** */
115 * Creates a new mode.
117 * @param name the name of the mode to be created
118 * @param sort the mode_sort of the mode to be created
119 * @param bit_size number of bits this mode allocate
120 * @param sign non-zero if this is a signed mode
121 * @param arithmetic arithmetic operations possible with a mode
122 * @param modulo_shift Is ignored for modes other than integer.
124 * This function constructs a new mode given by the parameters.
125 * If the parameters match an already defined mode, this mode is returned
126 * (including the default modes).
127 * If the mode is newly allocated, a new unique mode_code is chosen.
128 * Also, special value tarvals will be calculated such as null,
129 * min, max and can be retrieved using the get_mode_* functions
132 * The new mode or NULL on error.
135 * It is allowed to construct the default modes. So, a call
136 * new_ir_mode("Is", irms_int_number, 32, 1, irma_twos_complement, 32) will return mode_Is.
138 ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int sign, mode_arithmetic arithmetic, unsigned int modulo_shift);
141 * Creates a new vector mode.
143 * @param name the name of the mode to be created
144 * @param sort the mode_sort of the mode to be created
145 * @param bit_size number of bits for one element of this mode
146 * @param num_of_elem number of elements in this vector mode
147 * @param sign non-zero if this is a signed mode
148 * @param arithmetic arithmetic operations possible with a mode
149 * @param modulo_shift Is ignored for modes other than integer.
151 * This function constructs a new vector mode given by the parameters.
152 * If the parameters match an already defined mode, this mode is returned.
153 * If the mode is newly allocated, a new unique mode_code is chosen.
154 * Also, special value tarvals will be calculated such as null,
155 * min, max and can be retrieved using the get_mode_* functions
158 * The new mode or NULL on error.
160 ir_mode *new_ir_vector_mode(const char *name, mode_sort sort, int bit_size, unsigned num_of_elem, int sign,
161 mode_arithmetic arithmetic, unsigned int modulo_shift);
164 * Checks whether a pointer points to a mode.
166 * @param thing an arbitrary pointer
169 * true if the thing is a mode, else false
171 int is_mode(void *thing);
173 /* ********** Access methods to read mode information *********** */
175 /** Returns the classification of the mode */
176 modecode get_mode_modecode(const ir_mode *mode);
178 /** Returns the ident* of the mode */
179 ident *get_mode_ident(const ir_mode *mode);
181 /** Returns the null-terminated name of this mode. */
182 const char *get_mode_name(const ir_mode *mode);
184 /** Returns a coarse classification of the mode. */
185 mode_sort get_mode_sort(const ir_mode *mode);
187 /** Returns the size of values of the mode in bits. */
188 int get_mode_size_bits(const ir_mode *mode);
190 /** Returns the size of values of the mode in bytes.
191 * If the size is not dividable by 8 returns -1. */
192 int get_mode_size_bytes(const ir_mode *mode);
194 /** Returns the signess of a mode.
196 * Returns the signess of a mode: 1 if mode is signed. */
197 int get_mode_sign(const ir_mode *mode);
199 /** Returns the arithmetic of a mode */
200 int get_mode_arithmetic(const ir_mode *mode);
202 /** Get the modulo shift attribute.
204 * Attribute modulo shift specifies for modes of kind irms_int_number
205 * whether shift applies modulo to value of bits to shift. Zero for
206 * modes that are not integer.
208 unsigned int get_mode_modulo_shift(const ir_mode *mode);
210 /** Return the number of vector elements.
212 * Attribute vector_elem specifies the number of vector elements of
213 * a vector mode. For non-vector modes it returns 1 for data and 0
214 * for all other modes
216 unsigned int get_mode_n_vector_elems(const ir_mode *mode);
218 /** Returns the stored intermediate information. */
219 void *get_mode_link(const ir_mode *mode);
221 /** Stores new intermediate information. */
222 void set_mode_link(ir_mode *mode, void *l);
225 * Returns the smallest representable value of a given mode.
227 * For modes of the sort float_number this is the most negative value
228 * bigger than -infinite.
230 tarval *get_mode_min(ir_mode *mode);
233 * Returns the biggest representable value o f a given mode.
235 * For modes of the sort float_number this is the largest value lower
238 tarval *get_mode_max(ir_mode *mode);
241 * Returns the value Zero represented in this mode.
243 * Zero is the additive neutral element and as such
244 * is defined only for modes allowing addition, i.e.
245 * op_pin_state_floats and ints, and references (NULL-Pointer)
246 * else returns tarval_bad.
248 tarval *get_mode_null(ir_mode *mode);
251 * Returns the value One, represented in this mode.
253 * One, being the multiplicative neutral element,
254 * is defined only for modes allowing multiplication,
255 * i.e. ints and floats.
257 tarval *get_mode_one(ir_mode *mode);
260 * Returns the value Minus One, represented in this mode.
262 * Minus One is defined only for modes allowing
263 * multiplication with signed values, i.e. signed ints and floats.
265 tarval *get_mode_minus_one(ir_mode *mode);
268 * Returns the positive infinite value of a mode.
270 * This is only valid for float_numbers, other modes
271 * will result in tarval_bad.
273 tarval *get_mode_infinite(ir_mode *mode);
276 * Returns the NAN value of a given mode.
278 * This is only valid for float_numbers, other modes
279 * will result in tarval_bad.
281 tarval *get_mode_NAN(ir_mode *mode);
283 extern ir_mode *mode_M; /**< memory */
285 /* -- A set of predefined, numerical modes according to Techreport 1999-44 -- */
286 extern ir_mode *mode_F; /**< signed float(32) */
287 extern ir_mode *mode_D; /**< signed double(64) */
288 extern ir_mode *mode_E; /**< signed extended(80) */
289 extern ir_mode *mode_Bs; /**< signed byte (former char) */
290 extern ir_mode *mode_Bu; /**< unsigned byte (former char) */
291 extern ir_mode *mode_Hs; /**< signed short integer */
292 extern ir_mode *mode_Hu; /**< unsigned short integer */
293 extern ir_mode *mode_Is; /**< signed integer */
294 extern ir_mode *mode_Iu; /**< unsigned integer */
295 extern ir_mode *mode_Ls; /**< signed long integer */
296 extern ir_mode *mode_Lu; /**< unsigned long integer */
297 extern ir_mode *mode_LLs; /**< signed long long integer */
298 extern ir_mode *mode_LLu; /**< unsigned long long integer */
300 extern ir_mode *mode_P; /**< pointer */
301 extern ir_mode *mode_P_code; /**< A pointer mode that is set by the client of libfirm. This mode
302 represents the pointer size of the target machine code addresses. Is initialized
304 extern ir_mode *mode_P_data; /**< A pointer mode that is set by the client of libfirm. This mode
305 represents the pointer size of the target machine data addresses. Is initialized
308 /* -- Auxiliary modes necessary for the Firm representation -- */
309 extern ir_mode *mode_b; /**< internal boolean */
311 extern ir_mode *mode_X; /**< execution */
312 extern ir_mode *mode_BB; /**< block */
314 extern ir_mode *mode_T; /**< tuple (none) */
315 extern ir_mode *mode_ANY;/**< undefined mode */
316 extern ir_mode *mode_BAD;/**< bad mode */
319 /** Access routines for JNI Interface */
320 ir_mode *get_modeF(void);
321 ir_mode *get_modeD(void);
322 ir_mode *get_modeE(void);
323 ir_mode *get_modeBs(void);
324 ir_mode *get_modeBu(void);
325 ir_mode *get_modeHs(void);
326 ir_mode *get_modeHu(void);
327 ir_mode *get_modeIs(void);
328 ir_mode *get_modeIu(void);
329 ir_mode *get_modeLs(void);
330 ir_mode *get_modeLu(void);
331 ir_mode *get_modeLLs(void);
332 ir_mode *get_modeLLu(void);
333 ir_mode *get_modeP(void);
334 ir_mode *get_modeb(void);
335 ir_mode *get_modeX(void);
336 ir_mode *get_modeBB(void);
337 ir_mode *get_modeM(void);
338 ir_mode *get_modeT(void);
339 ir_mode *get_modeANY(void);
340 ir_mode *get_modeBAD(void);
342 /** Returns the machine specific pointer mode for code addresses. */
343 ir_mode *get_modeP_code(void);
345 /** Returns the machine specific pointer mode for data addresses. */
346 ir_mode *get_modeP_data(void);
349 * Sets the machine specific pointer mode for code addresses.
350 * If not set, the predefined mode mode_P will be used.
352 void set_modeP_code(ir_mode *p);
355 * Sets the machine specific pointer mode for data addresses.
356 * If not set, the predefined mode mode_P will be used.
358 void set_modeP_data(ir_mode *p);
361 Functions to check, whether a modecode is signed, float, int, character,
362 reference, num, data, datab or dataM.
364 For more exact definitions read the corresponding pages
365 in the firm documentation or the following enumeration
367 The set of "float" is defined as:
368 float = {irm_F, irm_D, irm_E}
370 The set of "int" is defined as:
371 int = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
373 The set of "reference" is defined as:
376 The set of "num" is defined as:
379 The set of "data" is defined as:
380 data = {num || reference}
382 The set of "datab" is defined as:
383 datab = {data || irm_b }
385 The set of "dataM" is defined as:
386 dataM = {data || irm_M}
388 Vector "int" and "float" are defined by the arithmetic and vector_elem > 1.
391 /* Test for a certain class of modes. */
392 int mode_is_signed (const ir_mode *mode);
393 int mode_is_float (const ir_mode *mode);
394 int mode_is_int (const ir_mode *mode);
395 int mode_is_reference (const ir_mode *mode);
396 int mode_is_num (const ir_mode *mode);
397 int mode_is_data (const ir_mode *mode);
398 int mode_is_datab (const ir_mode *mode);
399 int mode_is_dataM (const ir_mode *mode);
400 int mode_is_float_vector (const ir_mode *mode);
401 int mode_is_int_vector (const ir_mode *mode);
403 /** Returns true if sm can be converted to lm without loss
404 according to firm definition */
405 int smaller_mode(const ir_mode *sm, const ir_mode *lm);
408 * Returns a matching unsigned mode for a given integer signed mode.
409 * Returns NULL if no matching mode exists.
411 ir_mode *find_unsigned_mode(const ir_mode *mode);
414 * Returns a matching signed mode for a given integer unsigned mode.
415 * Returns NULL if no matching mode exists.
417 ir_mode *find_signed_mode(const ir_mode *mode);
420 * Returns an integer mode with 2*n bits for a given integer mode with n bits.
421 * Returns NULL if no matching mode exists.
423 ir_mode *find_double_bits_int_mode(const ir_mode *mode);
426 * Returns non-zero if the given mode honors signed zero's, i.e.,
427 * a +0 and a -0 exists and handled differently.
429 int mode_honor_signed_zeros(const ir_mode *mode);
432 * Returns non-zero if the given mode might overflow on unary Minus.
434 int mode_overflow_on_unary_Minus(const ir_mode *mode);
437 * Returns non-zero if the mode has a reversed wrap-around
438 * logic, especially (a + x) - x == a.
439 * This is normally true for integer modes, not for floating
442 int mode_wrap_around(const ir_mode *mode);
445 * Return the signed integer equivalent mode for an reference mode.
447 ir_mode *get_reference_mode_signed_eq(ir_mode *mode);
450 * Sets the signed integer equivalent mode for an reference mode.
452 void set_reference_mode_signed_eq(ir_mode *ref_mode, ir_mode *int_mode);
455 * Return the unsigned integer equivalent mode for an reference mode.
457 ir_mode *get_reference_mode_unsigned_eq(ir_mode *mode);
460 * Sets the unsigned integer equivalent mode for an reference mode.
462 void set_reference_mode_unsigned_eq(ir_mode *ref_mode, ir_mode *int_mode);