removed the exc_region attribute: not needed anymore
[libfirm] / include / libfirm / irmode.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Data modes of operations.
23  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Mathias Heil,
24  *          Michael Beck
25  * @version $Id$
26  * @summary
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
30  *  predefined modes.
31  *
32  *  SEE ALSO:
33  *    UKA tech report 1999-44 for more information about modes.
34  */
35 #ifndef FIRM_IR_IRMODE_H
36 #define FIRM_IR_IRMODE_H
37
38 #include "firm_types.h"
39 #include "ident.h"
40
41 /* ********** Predefined modes ********** */
42
43 /**
44  * Predefined mode according to tech report 1999-14.
45  */
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 */
65         irm_M,                        /**< memory */
66         irm_T,                        /**< tuple */
67         irm_U,                        /**< unicode character */
68         irm_ANY,                      /**< undefined mode */
69         irm_BAD,                      /**< bad mode */
70         irm_max                       /**< maximum value for modecode */
71 } modecode;
72
73 /** These values represent the different mode classes of value representations.
74  */
75 typedef enum {
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 */
89         irms_character          /**< A mode to represent characters/symbols
90                                      ?? Are computations allowed? as int?? */
91 } mode_sort;
92
93 /** These values represent the different arithmetic operations possible with a mode.
94     Further arithmetics can be defined, e.g., for @@@ modes.
95  */
96 typedef enum {
97         irma_uninitialized = 0,
98         irma_none = 1,              /**< For modes for which no representation is specified.
99                                          These are modes of sort auxiliary, internal_boolean and character. */
100         irma_twos_complement = 2,   /**< Values of the mode are represented as two's complement.
101                                      Only legal for modes of sort int_number and reference. */
102         irma_ones_complement,       /**< Values of the mode are represented  as one's complement.
103                                          Only legal for modes of sort int_number and reference. */
104         irma_int_BCD,               /**< Values of the mode are represented as binary coded decimals.
105                                          Only legal for modes of sort int_number and reference. */
106         irma_ieee754 = 256,         /**< Values of the mode are represented according to ieee754
107                                      floatingpoint standard.  Only legal for modes of sort float_number. */
108         irma_float_BCD,             /**< Values of the mode are represented  as binary coded decimals
109                                          according to @@@ which standards??? Only legal for modes of
110                                          sort float_number. */
111         irma_max
112 } mode_arithmetic;
113
114
115 /* ********** Constructor for user defined modes **************** */
116 /**
117  * Creates a new mode.
118  *
119  * @param name          the name of the mode to be created
120  * @param sort          the mode_sort of the mode to be created
121  * @param bit_size      number of bits this mode allocate
122  * @param sign          non-zero if this is a signed mode
123  * @param arithmetic    arithmetic operations possible with a mode
124  * @param modulo_shift  Is ignored for modes other than integer.
125  *
126  * This function constructs a new mode given by the parameters.
127  * If the parameters match an already defined mode, this mode is returned
128  * (including the default modes).
129  * If the mode is newly allocated, a new unique mode_code is chosen.
130  * Also, special value tarvals will be calculated such as null,
131  * min, max and can be retrieved using the get_mode_* functions
132  *
133  * @return
134  *   The new mode or NULL on error.
135  *
136  * @note
137  *   It is allowed to construct the default modes. So, a call
138  *   new_ir_mode("Is", irms_int_number, 32, 1, irma_twos_complement, 32) will return mode_Is.
139  */
140 ir_mode *new_ir_mode(const char *name, mode_sort sort, int bit_size, int sign, mode_arithmetic arithmetic, unsigned int modulo_shift);
141
142 /**
143  * Creates a new vector mode.
144  *
145  * @param name          the name of the mode to be created
146  * @param sort          the mode_sort of the mode to be created
147  * @param bit_size      number of bits for one element of this mode
148  * @param num_of_elem   number of elements in this vector mode
149  * @param sign          non-zero if this is a signed mode
150  * @param arithmetic    arithmetic operations possible with a mode
151  * @param modulo_shift  Is ignored for modes other than integer.
152  *
153  * This function constructs a new vector mode given by the parameters.
154  * If the parameters match an already defined mode, this mode is returned.
155  * If the mode is newly allocated, a new unique mode_code is chosen.
156  * Also, special value tarvals will be calculated such as null,
157  * min, max and can be retrieved using the get_mode_* functions
158  *
159  * @return
160  *   The new mode or NULL on error.
161  */
162 ir_mode *new_ir_vector_mode(const char *name, mode_sort sort, int bit_size, unsigned num_of_elem, int sign,
163                             mode_arithmetic arithmetic, unsigned int modulo_shift);
164
165 /**
166  * Checks whether a pointer points to a mode.
167  *
168  * @param thing     an arbitrary pointer
169  *
170  * @return
171  *     true if the thing is a mode, else false
172  */
173 int is_mode(void *thing);
174
175 /* ********** Access methods to read mode information *********** */
176
177 /** Returns the classification of the mode */
178 modecode    get_mode_modecode(const ir_mode *mode);
179
180 /** Returns the ident* of the mode */
181 ident      *get_mode_ident(const ir_mode *mode);
182
183 /** Returns the null-terminated name of this mode. */
184 const char *get_mode_name(const ir_mode *mode);
185
186 /** Returns a coarse classification of the mode. */
187 mode_sort   get_mode_sort(const ir_mode *mode);
188
189 /** Returns the size of values of the mode in bits. */
190 int get_mode_size_bits(const ir_mode *mode);
191
192 /** Returns the size of values of the mode in bytes.
193  *  If the size is not dividable by 8 returns -1. */
194 int get_mode_size_bytes(const ir_mode *mode);
195
196 /** Returns the signess of a mode.
197  *
198  * Returns the signess of a mode: 1 if mode is signed. */
199 int get_mode_sign(const ir_mode *mode);
200
201 /** Returns the arithmetic of a mode */
202 int get_mode_arithmetic(const ir_mode *mode);
203
204 /** Get the modulo shift attribute.
205  *
206  *  Attribute modulo shift specifies for modes of kind irms_int_number
207  *  whether shift applies modulo to value of bits to shift.  Zero for
208  *  modes that are not integer.
209  */
210 unsigned int get_mode_modulo_shift(const ir_mode *mode);
211
212 /** Return the number of vector elements.
213  *
214  *  Attribute vector_elem specifies the number of vector elements of
215  *  a vector mode. For non-vector modes it returns 1 for data and 0
216  *  for all other modes
217  */
218 unsigned int get_mode_n_vector_elems(const ir_mode *mode);
219
220 /** Returns the stored intermediate information. */
221 void *get_mode_link(const ir_mode *mode);
222
223 /** Stores new intermediate information. */
224 void  set_mode_link(ir_mode *mode, void *l);
225
226 /**
227  * Returns the smallest representable value of a given mode.
228  *
229  * For modes of the sort float_number this is the most negative value
230  * bigger than -infinite.
231  */
232 tarval *get_mode_min(ir_mode *mode);
233
234 /**
235  * Returns the biggest representable value o f a given mode.
236  *
237  * For modes of the sort float_number this is the largest value lower
238  * than infinite.
239  */
240 tarval *get_mode_max(ir_mode *mode);
241
242 /**
243  * Returns the value Zero represented in this mode.
244  *
245  * Zero is the additive neutral element and as such
246  * is defined only for modes allowing addition, i.e.
247  * op_pin_state_floats and ints, and references (NULL-Pointer)
248  * else returns tarval_bad.
249  */
250 tarval *get_mode_null(ir_mode *mode);
251
252 /**
253  * Returns the value One, represented in this mode.
254  *
255  * One, being the multiplicative neutral element,
256  * is defined only for modes allowing multiplication,
257  * i.e. ints and floats.
258  */
259 tarval *get_mode_one(ir_mode *mode);
260
261 /**
262  * Returns the value Minus One, represented in this mode.
263  *
264  * Minus One is defined only for modes allowing
265  * multiplication with signed values, i.e. signed ints and floats.
266  */
267 tarval *get_mode_minus_one(ir_mode *mode);
268
269 /**
270  * Returns the positive infinite value of a mode.
271  *
272  * This is only valid for float_numbers, other modes
273  * will result in tarval_bad.
274  */
275 tarval *get_mode_infinite(ir_mode *mode);
276
277 /**
278  * Returns the NAN value of a given mode.
279  *
280  * This is only valid for float_numbers, other modes
281  * will result in tarval_bad.
282  */
283 tarval *get_mode_NAN(ir_mode *mode);
284
285 extern ir_mode *mode_M;  /**< memory */
286
287 /* -- A set of predefined, numerical modes according to Techreport 1999-44 -- */
288 extern ir_mode *mode_F;   /**< signed float(32) */
289 extern ir_mode *mode_D;   /**< signed double(64) */
290 extern ir_mode *mode_E;   /**< signed extended(80) */
291 extern ir_mode *mode_Bs;  /**< signed byte (former char) */
292 extern ir_mode *mode_Bu;  /**< unsigned byte (former char) */
293 extern ir_mode *mode_Hs;  /**< signed short integer */
294 extern ir_mode *mode_Hu;  /**< unsigned short integer */
295 extern ir_mode *mode_Is;  /**< signed integer */
296 extern ir_mode *mode_Iu;  /**< unsigned integer */
297 extern ir_mode *mode_Ls;  /**< signed long integer */
298 extern ir_mode *mode_Lu;  /**< unsigned long integer */
299 extern ir_mode *mode_LLs; /**< signed long long integer */
300 extern ir_mode *mode_LLu; /**< unsigned long long integer */
301
302 extern ir_mode *mode_C;   /**< 8 bit char */
303 extern ir_mode *mode_U;   /**< 16 bit unicode char */
304
305 extern ir_mode *mode_P;   /**< pointer */
306 extern ir_mode *mode_P_code; /**< A pointer mode that is set by the client of libfirm.  This mode
307                                   represents the pointer size of the target machine code addresses. Is initialized
308                                   to mode_P. */
309 extern ir_mode *mode_P_data; /**< A pointer mode that is set by the client of libfirm.  This mode
310                                   represents the pointer size of the target machine data addresses. Is initialized
311                                   to mode_P. */
312
313 /* -- Auxiliary modes necessary for the Firm representation -- */
314 extern ir_mode *mode_b;  /**< internal boolean */
315
316 extern ir_mode *mode_X;  /**< execution */
317 extern ir_mode *mode_BB; /**< block */
318
319 extern ir_mode *mode_T;  /**< tuple (none) */
320 extern ir_mode *mode_ANY;/**< undefined mode */
321 extern ir_mode *mode_BAD;/**< bad mode */
322
323 /*@{*/
324 /** Access routines for JNI Interface */
325 ir_mode *get_modeF(void);
326 ir_mode *get_modeD(void);
327 ir_mode *get_modeE(void);
328 ir_mode *get_modeBs(void);
329 ir_mode *get_modeBu(void);
330 ir_mode *get_modeHs(void);
331 ir_mode *get_modeHu(void);
332 ir_mode *get_modeIs(void);
333 ir_mode *get_modeIu(void);
334 ir_mode *get_modeLs(void);
335 ir_mode *get_modeLu(void);
336 ir_mode *get_modeLLs(void);
337 ir_mode *get_modeLLu(void);
338 ir_mode *get_modeC(void);
339 ir_mode *get_modeU(void);
340 ir_mode *get_modeP(void);
341 ir_mode *get_modeb(void);
342 ir_mode *get_modeX(void);
343 ir_mode *get_modeBB(void);
344 ir_mode *get_modeM(void);
345 ir_mode *get_modeT(void);
346 ir_mode *get_modeANY(void);
347 ir_mode *get_modeBAD(void);
348
349 /** Returns the machine specific pointer mode for code addresses. */
350 ir_mode *get_modeP_code(void);
351
352 /** Returns the machine specific pointer mode for data addresses. */
353 ir_mode *get_modeP_data(void);
354
355 /**
356  * Sets the machine specific pointer mode for code addresses.
357  * If not set, the predefined mode mode_P will be used.
358  */
359 void set_modeP_code(ir_mode *p);
360
361 /**
362  * Sets the machine specific pointer mode for data addresses.
363  * If not set, the predefined mode mode_P will be used.
364  */
365 void set_modeP_data(ir_mode *p);
366
367 /**
368    Functions to check, whether a modecode is signed, float, int, character,
369    reference, num, numP, data, datab or dataM.
370
371    For more exact definitions read the corresponding pages
372    in the firm documentation or the following enumeration
373
374    The set of "float" is defined as:
375    float = {irm_F, irm_D, irm_E}
376
377    The set of "int" is defined as:
378    int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
379
380    The set of "character" is defined as:
381    character  = {irm_C, irm_U}
382
383    The set of "reference" is defined as:
384    reference  = {irm_P}
385
386    The set of "num" is defined as:
387    num   = {float || int}
388
389    The set of "numP" is defined as:
390    numP  =  {float || int || reference}
391
392    The set of "data" is defined as:
393    data  =  {num || character || reference}
394
395    The set of "datab" is defined as:
396    datab =  {data || irm_b }
397
398    The set of "dataM" is defined as:
399    dataM =  {data || irm_M}
400
401    Vector "int" and "float" are defined by the arithmetic and vector_elem > 1.
402 */
403 /*@}*/
404 /* Test for a certain class of modes. */
405 int mode_is_signed (const ir_mode *mode);
406 int mode_is_float (const ir_mode *mode);
407 int mode_is_int (const ir_mode *mode);
408 int mode_is_character (const ir_mode *mode);
409 int mode_is_reference (const ir_mode *mode);
410 int mode_is_num (const ir_mode *mode);
411 int mode_is_numP (const ir_mode *mode);
412 int mode_is_data (const ir_mode *mode);
413 int mode_is_datab (const ir_mode *mode);
414 int mode_is_dataM (const ir_mode *mode);
415 int mode_is_float_vector (const ir_mode *mode);
416 int mode_is_int_vector (const ir_mode *mode);
417
418 /** Returns true if sm can be converted to lm without loss
419    according to firm definiton */
420 int smaller_mode(const ir_mode *sm, const ir_mode *lm);
421
422 /**
423  * Returns a matching unsigned mode for a given integer signed mode.
424  * Returns NULL if no matching mode exists.
425  */
426 ir_mode *find_unsigned_mode(const ir_mode *mode);
427
428 /**
429  * Returns a matching signed mode for a given integer unsigned mode.
430  * Returns NULL if no matching mode exists.
431  */
432 ir_mode *find_signed_mode(const ir_mode *mode);
433
434 /**
435  * Returns an integer mode with 2*n bits for a given integer mode with n bits.
436  * Returns NULL if no matching mode exists.
437  */
438 ir_mode *find_double_bits_int_mode(const ir_mode *mode);
439
440 /**
441  * Returns non-zero if the given mode honors signed zero's, i.e.,
442  * a +0 and a -0 exists and handled differently.
443  */
444 int mode_honor_signed_zeros(const ir_mode *mode);
445
446 /**
447  * Returns non-zero if the given mode might overflow on unary Minus.
448  */
449 int mode_overflow_on_unary_Minus(const ir_mode *mode);
450
451 /**
452  * Returns non-zero if the mode has a reversed wrap-around
453  * logic, especially (a + x) - x == a.
454  * This is normally true for integer modes, not for floating
455  * point modes.
456  */
457 int mode_wrap_around(const ir_mode *mode);
458
459 /**
460  * Return the signed integer equivalent mode for an reference mode.
461  */
462 ir_mode *get_reference_mode_signed_eq(ir_mode *mode);
463
464 /**
465  * Sets the signed integer equivalent mode for an reference mode.
466  */
467 void set_reference_mode_signed_eq(ir_mode *ref_mode, ir_mode *int_mode);
468
469 /**
470  * Return the unsigned integer equivalent mode for an reference mode.
471  */
472 ir_mode *get_reference_mode_unsigned_eq(ir_mode *mode);
473
474 /**
475  * Sets the unsigned integer equivalent mode for an reference mode.
476  */
477 void set_reference_mode_unsigned_eq(ir_mode *ref_mode, ir_mode *int_mode);
478
479 #endif