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 * Neccessary 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 unambigous 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 kategories
50 * - int size: size of the mode in Bits.
51 * - int align: byte alignment
52 * - unsigned sign:1: signedness of this mode
54 * - modulo_shift specifies for modes of kind irms_int_number
55 * whether shift applies modulo to value of bits to shift
58 * The tech report 1999-44 describing FIRM and predefined modes
61 typedef struct ir_mode ir_mode;
63 /* ********** Predefined modes ********** */
66 * Predefined mode according to tech report 1999-14.
68 typedef enum { /* irm is short for `ir mode' */
69 irm_BB, /**< basic block */
70 irm_X, /**< execution */
71 irm_F, /**< float(32) */
72 irm_D, /**< double(64) */
73 irm_E, /**< extended(80) */
74 irm_Bs, /**< signed byte(8) */
75 irm_Bu, /**< unsigned byte(8) */
76 irm_Hs, /**< signed short(16) */
77 irm_Hu, /**< unsigned short(16) */
78 irm_Is, /**< signed int(32) */
79 irm_Iu, /**< unsigned int(32) */
80 irm_Ls, /**< signed long(64) */
81 irm_Lu, /**< unsigned long(64) */
82 irm_C, /**< character */
83 irm_P, /**< pointer */
84 irm_b, /**< internal boolean */
87 irm_U, /**< unicode character */
88 irm_ANY, /**< undefined mode */
89 irm_BAD, /**< bad mode */
90 irm_max /**< maximum value for modecode */
93 /** These values represent the different mode classes of value representations.
96 /* Predefined sorts of modes */
97 irms_auxiliary, /**< Only for Firm use. Not extensible. (irm_T) */
98 irms_control_flow, /**< Marks all control flow modes. Not extensible. (irm_BB, irm_X) */
99 irms_memory, /**< Marks the memory mode. Not extensible. (irm_M) */
100 irms_internal_boolean, /**< Internal boolean representation.
101 Storing to memory impossible, convert first. (irm_b) */
102 /** user-extensible sorts of modes **/
103 irms_int_number, /**< A mode to represent int numbers.
104 Integer computations can be performed. */
105 irms_float_number, /**< A mode to represent float numbers.
106 Floating point computations can be performed. */
107 irms_reference, /**< A mode to represent entities.
108 Restricted int computations can be performed */
109 irms_character /**< A mode to represent characters/symbols
110 ?? Are computations allowed? as int?? */
113 /** These values represent the different arithmetic operations possible with a mode.
114 Further arithmetics can be defined, e.g., for @@@ modes.
117 irma_uninitialized = 0,
118 irma_none = 1, /**< For modes for which no representation is specified.
119 These are modes of sort auxiliary, internal_boolean and
121 irma_twos_complement = 2, /**< Values of the mode are represented as two's complement.
122 Only legal for modes of sort int_number and reference. */
123 irma_ones_complement, /**< Values of the mode are represented as one's complement.
124 Only legal for modes of sort int_number and reference. */
125 irma_int_BCD, /**< Values of the mode are represented as binary coded decimals.
126 Only legal for modes of sort int_number and reference. */
127 irma_ieee754 = 256, /**< Values of the mode are represented according to ieee754
128 floatingpoint standard. Only legal for modes of sort float_number. */
129 irma_float_BCD, /**< Values of the mode are represented as binary coded decimals
130 according to @@@ which standards??? Only legal for modes of
131 sort float_number. */
136 /* ********** Constructor for user defined modes **************** */
138 * Creates a new mode.
140 * @param name the name of the mode to be created
141 * @param sort the mode_sort of the mode to be created
142 * @param bit_size number of bits this mode allocate
143 * @param bit_align the alignment for an entity of this mode in bits
144 * @param sign non-zero if this is a signed mode
145 * @param arithmetic arithmetic operations possible with a mode
146 * @param modulo_shift Is ignored for modes other than integer.
148 * This function constructs a new mode given by the parameters.
149 * If the parameters match an already defined mode, this mode is returned
150 * (including the default modes).
151 * If the mode is newly allocated, a new unique mode_code is choosen.
152 * Also, special value tarvals will be calculated such as null,
153 * min, max and can be retrieved using the get_mode_* fuctions
156 * The new mode or NULL on error.
159 * It is allowed to construct the default modes. So, a call
160 * new_ir_mode("Is", irms_int_number, 32, 4, 1, irma_twos_complement, 32) will return mode_Is.
162 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);
165 * Creates a new vector mode.
167 * @param name the name of the mode to be created
168 * @param sort the mode_sort of the mode to be created
169 * @param bit_size number of bits for one element of this mode
170 * @param num_of_elem number of elements in this vector mode
171 * @param bit_align the alignment for an entity of this mode in bits
172 * @param sign non-zero if this is a signed mode
173 * @param arithmetic arithmetic operations possible with a mode
174 * @param modulo_shift Is ignored for modes other than integer.
176 * This function constructs a new vector mode given by the parameters.
177 * If the parameters match an already defined mode, this mode is returned.
178 * If the mode is newly allocated, a new unique mode_code is choosen.
179 * Also, special value tarvals will be calculated such as null,
180 * min, max and can be retrieved using the get_mode_* fuctions
183 * The new mode or NULL on error.
185 ir_mode *new_ir_vector_mode(const char *name, mode_sort sort, int bit_size, unsigned num_of_elem, int bit_align, int sign,
186 mode_arithmetic arithmetic, unsigned int modulo_shift );
189 * Checks whether a pointer points to a mode.
191 * @param thing an arbitrary pointer
194 * true if the thing is a mode, else false
196 int is_mode(void *thing);
198 /* ********** Access methods to read mode information *********** */
200 /** Returns the classification of the mode */
201 modecode get_mode_modecode(const ir_mode *mode);
203 /** Returns the ident* of the mode */
204 ident *get_mode_ident(const ir_mode *mode);
206 /** Returns the null-terminated name of this mode. */
207 const char *get_mode_name(const ir_mode *mode);
209 /** Returns a coarse classification of the mode. */
210 mode_sort get_mode_sort(const ir_mode *mode);
212 /** Returns the size of values of the mode in bits. */
213 int get_mode_size_bits(const ir_mode *mode);
215 /** Returns the size of values of the mode in bytes.
216 * If the size is not dividable by 8 returns -1. */
217 int get_mode_size_bytes(const ir_mode *mode);
219 /** Returns the alignment of values of the mode in bits. */
220 int get_mode_align_bits(const ir_mode *mode);
222 /** Returns the alignment of values of the mode in bytes.
223 * If the alignment is not dividable by 8 returns -1. */
224 int get_mode_align_bytes(const ir_mode *mode);
226 /** Returns the signess of a mode.
228 * Returns the signess of a mode: 1 if mode is signed. */
229 int get_mode_sign(const ir_mode *mode);
231 /** Returns the arithmetic of a mode */
232 int get_mode_arithmetic(const ir_mode *mode);
234 /** Attribute modulo shift specifies for modes of kind irms_int_number
235 * whether shift applies modulo to value of bits to shift. Zero for
236 * modes that are not integer.
238 unsigned int get_mode_modulo_shift(const ir_mode *mode);
240 /** Attribute vector_elem specifies the number of vector elements of
241 * a vector mode. For non-vector modes it returns 1 for data and 0
242 * for all other modes
244 unsigned int get_mode_vector_elems(const ir_mode *mode);
246 /** Returns the stored intermediate information. */
247 void* get_mode_link(const ir_mode *mode);
249 /** Stores new intermediate information. */
250 void set_mode_link(ir_mode *mode, void *l);
253 * Returns the smallest representable value of a given mode.
255 * For modes of the sort float_number this is the most negative value
256 * bigger than -infinit.
258 tarval *get_mode_min(ir_mode *mode);
261 * Returns the biggest representable value o f a given mode.
263 * For modes of the sort float_number this is the largest value lower
266 tarval *get_mode_max(ir_mode *mode);
269 * Returns the value Zero represented in this mode.
271 * Zero is the additive neutral element and as such
272 * is defined only for modes allowing addition, i.e.
273 * floats and ints, and references (NULL-Pointer)
274 * else returns tarval_bad.
276 tarval *get_mode_null(ir_mode *mode);
279 * Returns the value One, represented in this mode.
281 * One, being the multiplicative neutral element,
282 * is defined only for modes allowing multiplication,
283 * i.e. ints and floats.
285 tarval *get_mode_one(ir_mode *mode);
288 * Returns the positive infinite value of a mode.
290 * This is only valid for float_numbers, other modes
291 * will result in tarval_bad.
293 tarval *get_mode_infinite(ir_mode *mode);
296 * Returns the NAN value of a given mode.
298 * This is only valid for float_numbers, other modes
299 * will result in tarval_bad.
301 tarval *get_mode_NAN(ir_mode *mode);
303 extern ir_mode *mode_M; /**< memory */
305 /* -- A set of predifined, numerical modes according to Techreport 1999-44 -- */
306 extern ir_mode *mode_F; /**< signed float(32) */
307 extern ir_mode *mode_D; /**< signed double(64) */
308 extern ir_mode *mode_E; /**< signed extended(80) */
309 extern ir_mode *mode_Bs; /**< signed byte (former char) */
310 extern ir_mode *mode_Bu; /**< unsigned byte (former char) */
311 extern ir_mode *mode_Hs; /**< signed short integer */
312 extern ir_mode *mode_Hu; /**< unsigened short integer */
313 extern ir_mode *mode_Is; /**< signed integer */
314 extern ir_mode *mode_Iu; /**< unsigned integer */
315 extern ir_mode *mode_Ls; /**< signed long integer */
316 extern ir_mode *mode_Lu; /**< unsigned long integer */
318 extern ir_mode *mode_C; /**< 8 bit char */
319 extern ir_mode *mode_U; /**< 16 bit unicode char */
321 extern ir_mode *mode_P; /**< pointer */
322 extern ir_mode *mode_P_mach; /**< A pointer mode that is set by the client of libfirm. This mode
323 represents the pointer size of the target machine. Is initialized
326 /* -- Auxiliary modes necessary for the Firm representation -- */
327 extern ir_mode *mode_b; /**< internal boolean */
329 extern ir_mode *mode_X; /**< execution */
330 extern ir_mode *mode_BB; /**< block */
332 extern ir_mode *mode_T; /**< tuple (none) */
333 extern ir_mode *mode_ANY;/**< undefined mode */
334 extern ir_mode *mode_BAD;/**< bad mode */
337 /** Access routines for JNI Interface */
338 ir_mode *get_modeF(void);
339 ir_mode *get_modeD(void);
340 ir_mode *get_modeE(void);
341 ir_mode *get_modeBs(void);
342 ir_mode *get_modeBu(void);
343 ir_mode *get_modeHs(void);
344 ir_mode *get_modeHu(void);
345 ir_mode *get_modeIs(void);
346 ir_mode *get_modeIu(void);
347 ir_mode *get_modeLs(void);
348 ir_mode *get_modeLu(void);
349 ir_mode *get_modeC(void);
350 ir_mode *get_modeU(void);
351 ir_mode *get_modeP(void);
352 ir_mode *get_modeb(void);
353 ir_mode *get_modeX(void);
354 ir_mode *get_modeBB(void);
355 ir_mode *get_modeM(void);
356 ir_mode *get_modeT(void);
357 ir_mode *get_modeANY(void);
358 ir_mode *get_modeBAD(void);
360 /** Returns the machine specific pointer mode. */
361 ir_mode *get_modeP_mach(void);
364 * Sets the machine specific pointer mode.
365 * If not set, the predefined mode mode_P will be used.
367 void set_modeP_mach(ir_mode *p);
370 Functions to check, whether a modecode is signed, float, int, character,
371 reference, num, numP, data, datab or dataM.
373 For more exact definitions read the corresponding pages
374 in the firm documentation or the following enumeration
376 The set of "float" is defined as:
377 float = {irm_F, irm_D, irm_E}
379 The set of "int" is defined as:
380 int = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
382 The set of "character" is defined as:
383 character = {irm_C, irm_U}
385 The set of "reference" is defined as:
388 The set of "num" is defined as:
391 The set of "numP" is defined as:
392 numP = {float || int || reference}
394 The set of "data" is defined as:
395 data = {num || character || reference}
397 The set of "datab" is defined as:
398 datab = {data || irm_b }
400 The set of "dataM" is defined as:
401 dataM = {data || irm_M}
403 Vector "int" and "float" are defined by the arithmetic and vector_elem > 1.
406 /* Test for a certain class of modes. */
407 int mode_is_signed (const ir_mode *mode);
408 int mode_is_float (const ir_mode *mode);
409 int mode_is_int (const ir_mode *mode);
410 int mode_is_character (const ir_mode *mode);
411 int mode_is_reference (const ir_mode *mode);
412 int mode_is_num (const ir_mode *mode);
413 int mode_is_numP (const ir_mode *mode);
414 int mode_is_data (const ir_mode *mode);
415 int mode_is_datab (const ir_mode *mode);
416 int mode_is_dataM (const ir_mode *mode);
417 int mode_is_float_vector (const ir_mode *mode);
418 int mode_is_int_vector (const ir_mode *mode);
420 /** Returns true if sm can be converted to lm without loss
421 according to firm definiton */
422 int smaller_mode(const ir_mode *sm, const ir_mode *lm);
424 /** mode module initialization, call once before use of any other function **/
425 void init_mode(void);
427 /** mode module finalization. frees all memory. */
428 void finish_mode(void);
430 #endif /* _IRMODE_H_ */