becopyopt: Inline the thin wrapper nodes_interfere(), so we do not need to fetch...
[libfirm] / include / libfirm / irmode.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief   Data modes of operations.
9  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Mathias Heil,
10  *          Michael Beck
11  */
12 #ifndef FIRM_IR_IRMODE_H
13 #define FIRM_IR_IRMODE_H
14
15 #include "firm_types.h"
16 #include "begin.h"
17
18 #include <stddef.h>
19
20 /**
21  * @defgroup ir_mode Value Modes
22  *  This module specifies the modes that type the firm nodes.  It defines
23  *  a datasturcture that describes a mode and implements constructors and
24  *  access routines to this datastructure. Further it defines a set of
25  *  predefined modes.
26  *
27  *  SEE ALSO:
28  *    UKA tech report 1999-44 for more information about modes.
29  * @{
30  */
31
32 /**
33  * These values represent the different arithmetic operations possible with a
34  * mode.
35  */
36 typedef enum ir_mode_arithmetic {
37         irma_none = 1,            /**< For modes for which no representation is
38                                        specified. These are modes of sort auxiliary,
39                                        internal_boolean and character. */
40         irma_twos_complement = 2, /**< Values of the mode are represented as two's
41                                        complement. Only legal for modes of sort
42                                        int_number and reference. */
43         irma_ieee754 = 256,       /**< Values of the mode are represented according
44                                        to ieee754 floating point standard.  Only
45                                        legal for modes of sort float_number. */
46         irma_x86_extended_float,  /**< x86 extended floatingpoint values */
47         irma_last = irma_x86_extended_float,
48 } ir_mode_arithmetic;
49
50 /**
51  * Creates a new mode.
52  *
53  * @param name          the name of the mode to be created
54  * @param arithmetic    arithmetic operations possible with a mode
55  * @param bit_size      number of bits this mode allocate
56  * @param sign          non-zero if this is a signed mode
57  * @param modulo_shift  Is ignored for modes other than integer.
58  *
59  * This function constructs a new mode given by the parameters.
60  * If the parameters match an already defined mode, this mode is returned
61  * (including the default modes).
62  *
63  * @return
64  *   The new mode or NULL on error.
65  */
66 FIRM_API ir_mode *new_int_mode(const char *name,
67                                ir_mode_arithmetic arithmetic,
68                                unsigned bit_size, int sign,
69                                unsigned modulo_shift);
70
71 /**
72  * Create a new reference mode.
73  *
74  * Reference modes are always unsigned.
75  */
76 FIRM_API ir_mode *new_reference_mode(const char *name,
77                                      ir_mode_arithmetic arithmetic,
78                                      unsigned bit_size,
79                                      unsigned modulo_shift);
80
81 /**
82  * Create a new ieee754 float mode.
83  *
84  * float-modes are always signed and have no modulo shift.
85  * @param name          the name of the mode to be created
86  * @param arithmetic    arithmetic/representation of the mode
87  * @param exponent_size size of exponent in bits
88  * @param mantissa_size size of mantissa in bits (number of bits after the
89  *                      leading one).
90  */
91 FIRM_API ir_mode *new_float_mode(const char *name,
92                                  ir_mode_arithmetic arithmetic,
93                                  unsigned exponent_size,
94                                  unsigned mantissa_size);
95
96 /**
97  * Checks whether a pointer points to a mode.
98  *
99  * @param thing     an arbitrary pointer
100  *
101  * @return
102  *     true if the thing is a mode, else false
103  */
104 FIRM_API int is_mode(const void *thing);
105
106 /** Returns the ident* of the mode */
107 FIRM_API ident *get_mode_ident(const ir_mode *mode);
108
109 /** Returns the null-terminated name of this mode. */
110 FIRM_API const char *get_mode_name(const ir_mode *mode);
111
112 /** Returns the size of values of the mode in bits. */
113 FIRM_API unsigned get_mode_size_bits(const ir_mode *mode);
114
115 /** Returns the size of values of the mode in bytes.
116  *  If the size is not dividable by 8 returns -1. */
117 FIRM_API unsigned get_mode_size_bytes(const ir_mode *mode);
118
119 /** Returns the signess of a mode.
120  *
121  * Returns the signess of a mode: 1 if mode is signed. */
122 FIRM_API int get_mode_sign(const ir_mode *mode);
123
124 /** Returns the arithmetic of a mode */
125 FIRM_API ir_mode_arithmetic get_mode_arithmetic(const ir_mode *mode);
126
127 /** Returns the modulo shift attribute.
128  *
129  *  Attribute modulo shift specifies for modes of kind irms_int_number
130  *  whether shift applies modulo to value of bits to shift.  Zero for
131  *  modes that are not integer.
132  */
133 FIRM_API unsigned int get_mode_modulo_shift(const ir_mode *mode);
134
135 /** Returns the stored intermediate information. */
136 FIRM_API void *get_mode_link(const ir_mode *mode);
137
138 /** Stores new intermediate information. */
139 FIRM_API void set_mode_link(ir_mode *mode, void *l);
140
141 /**
142  * Returns the smallest representable value of a given mode.
143  *
144  * For modes of the sort float_number this is the most negative value
145  * bigger than -infinite.
146  */
147 FIRM_API ir_tarval *get_mode_min(ir_mode *mode);
148
149 /**
150  * Returns the biggest representable value o f a given mode.
151  *
152  * For modes of the sort float_number this is the largest value lower
153  * than infinite.
154  */
155 FIRM_API ir_tarval *get_mode_max(ir_mode *mode);
156
157 /**
158  * Returns the value Zero represented in this mode.
159  *
160  * Zero is the additive neutral element and as such
161  * is defined only for modes allowing addition, i.e.
162  * op_pin_state_floats and ints, and references (NULL-Pointer)
163  * else returns tarval_bad.
164  */
165 FIRM_API ir_tarval *get_mode_null(ir_mode *mode);
166
167 /**
168  * Returns the value One, represented in this mode.
169  *
170  * One, being the multiplicative neutral element,
171  * is defined only for modes allowing multiplication,
172  * i.e. ints and floats.
173  */
174 FIRM_API ir_tarval *get_mode_one(ir_mode *mode);
175
176 /**
177  * Returns the value Minus One, represented in this mode.
178  *
179  * Minus One is defined only for modes allowing
180  * multiplication with signed values, i.e. signed ints and floats.
181  */
182 FIRM_API ir_tarval *get_mode_minus_one(ir_mode *mode);
183
184 /**
185  * Returns the value where all bits are One, represented in this mode.
186  *
187  * All One is defined only for modes integer, reference and boolean modes
188  */
189 FIRM_API ir_tarval *get_mode_all_one(ir_mode *mode);
190
191 /**
192  * Returns the positive infinite value of a mode.
193  *
194  * This is only valid for float_numbers, other modes
195  * will result in tarval_bad.
196  */
197 FIRM_API ir_tarval *get_mode_infinite(ir_mode *mode);
198
199 /**
200  * Returns the NAN value of a given mode.
201  *
202  * This is only valid for float_numbers, other modes
203  * will result in tarval_bad.
204  */
205 FIRM_API ir_tarval *get_mode_NAN(ir_mode *mode);
206
207 FIRM_API ir_mode *mode_M; /**< memory */
208
209 FIRM_API ir_mode *mode_F;   /**< ieee754 binary32 float (single precision) */
210 FIRM_API ir_mode *mode_D;   /**< ieee754 binary64 float (double precision) */
211 FIRM_API ir_mode *mode_Q;   /**< ieee754 binary128 float (quadruple precision)*/
212 FIRM_API ir_mode *mode_Bs;  /**< int8 */
213 FIRM_API ir_mode *mode_Bu;  /**< uint8 */
214 FIRM_API ir_mode *mode_Hs;  /**< int16 */
215 FIRM_API ir_mode *mode_Hu;  /**< uint16 */
216 FIRM_API ir_mode *mode_Is;  /**< int32 */
217 FIRM_API ir_mode *mode_Iu;  /**< uint32 */
218 FIRM_API ir_mode *mode_Ls;  /**< int64 */
219 FIRM_API ir_mode *mode_Lu;  /**< uint64 */
220 FIRM_API ir_mode *mode_LLs; /**< int128 */
221 FIRM_API ir_mode *mode_LLu; /**< uint128 */
222
223 FIRM_API ir_mode *mode_P;   /**< pointer */
224 FIRM_API ir_mode *mode_P_code; /**< A pointer mode that is set by the client of libfirm.  This mode
225                                   represents the pointer size of the target machine code addresses. Is initialized
226                                   to mode_P. */
227 FIRM_API ir_mode *mode_P_data; /**< A pointer mode that is set by the client of libfirm.  This mode
228                                   represents the pointer size of the target machine data addresses. Is initialized
229                                   to mode_P. */
230
231 FIRM_API ir_mode *mode_b;  /**< internal boolean */
232
233 FIRM_API ir_mode *mode_X;  /**< execution */
234 FIRM_API ir_mode *mode_BB; /**< block */
235
236 FIRM_API ir_mode *mode_T;  /**< tuple (none) */
237 FIRM_API ir_mode *mode_ANY;/**< undefined mode */
238 FIRM_API ir_mode *mode_BAD;/**< bad mode */
239
240 /** Returns float mode */
241 FIRM_API ir_mode *get_modeF(void);
242 /** Returns double mode */
243 FIRM_API ir_mode *get_modeD(void);
244 /** Returns quadruple prevision mode */
245 FIRM_API ir_mode *get_modeQ(void);
246 /** Returns byte signed mode */
247 FIRM_API ir_mode *get_modeBs(void);
248 /** Returns byte unsigned mode */
249 FIRM_API ir_mode *get_modeBu(void);
250 /** Returns halfword signed mode */
251 FIRM_API ir_mode *get_modeHs(void);
252 /** Returns halfword unsigned mode */
253 FIRM_API ir_mode *get_modeHu(void);
254 /** Returns integer signed mode */
255 FIRM_API ir_mode *get_modeIs(void);
256 /** Returns integer unsigned mode */
257 FIRM_API ir_mode *get_modeIu(void);
258 /** Returns long signed mode */
259 FIRM_API ir_mode *get_modeLs(void);
260 /** Returns long unsigned mode */
261 FIRM_API ir_mode *get_modeLu(void);
262 /** Returns long long signed mode */
263 FIRM_API ir_mode *get_modeLLs(void);
264 /** Returns long long unsigned mode */
265 FIRM_API ir_mode *get_modeLLu(void);
266 /** Returns pointer mode */
267 FIRM_API ir_mode *get_modeP(void);
268 /** Returns internal boolean mode */
269 FIRM_API ir_mode *get_modeb(void);
270 /** Returns control-flow mode */
271 FIRM_API ir_mode *get_modeX(void);
272 /** Returns Basic-Block mode */
273 FIRM_API ir_mode *get_modeBB(void);
274 /** Returns memory mode */
275 FIRM_API ir_mode *get_modeM(void);
276 /** Returns tuple mode */
277 FIRM_API ir_mode *get_modeT(void);
278 /** Returns ANY mode */
279 FIRM_API ir_mode *get_modeANY(void);
280 /** Returns BAD mode */
281 FIRM_API ir_mode *get_modeBAD(void);
282
283 /** Returns the machine specific pointer mode for code addresses. */
284 FIRM_API ir_mode *get_modeP_code(void);
285
286 /** Returns the machine specific pointer mode for data addresses. */
287 FIRM_API ir_mode *get_modeP_data(void);
288
289 /**
290  * Sets the machine specific pointer mode for code addresses.
291  * If not set, the predefined mode mode_P will be used.
292  */
293 FIRM_API void set_modeP_code(ir_mode *p);
294
295 /**
296  * Sets the machine specific pointer mode for data addresses.
297  * If not set, the predefined mode mode_P will be used.
298  */
299 FIRM_API void set_modeP_data(ir_mode *p);
300
301 /** Returns 1 if @p mode is signed, 0 otherwise */
302 FIRM_API int mode_is_signed (const ir_mode *mode);
303 /** Returns 1 if @p mode is for floatingpoint numbers, 0 otherwise */
304 FIRM_API int mode_is_float (const ir_mode *mode);
305 /** Returns 1 if @p mode is for integer numbers, 0 otherwise */
306 FIRM_API int mode_is_int (const ir_mode *mode);
307 /** Returns 1 if @p mode is for references/pointers, 0 otherwise */
308 FIRM_API int mode_is_reference (const ir_mode *mode);
309 /** Returns 1 if @p mode is for numeric values, 0 otherwise */
310 FIRM_API int mode_is_num (const ir_mode *mode);
311 /** Returns 1 if @p mode is for data values, 0 otherwise */
312 FIRM_API int mode_is_data (const ir_mode *mode);
313 /** Returns 1 if @p mode is for data values or internal booleans, 0 otherwise */
314 FIRM_API int mode_is_datab (const ir_mode *mode);
315 /** Returns 1 if @p mode is for data values or memory, 0 otherwise */
316 FIRM_API int mode_is_dataM (const ir_mode *mode);
317
318 /**
319  * Returns true if a value of mode @p sm can be converted to mode @p lm without
320  * loss.
321  *
322  * That is the interpretation of the numbers does not changes, so you a signed
323  * integer mode is never smaller than an unsigned integer mode since the
324  * unsigned mode can't represent negative numbers in a way that they are
325  * interpreted as negative numbers.
326  *
327  * @see values_in_mode()
328  */
329 FIRM_API int smaller_mode(const ir_mode *sm, const ir_mode *lm);
330
331 /**
332  * Returns true if no information is lost when converting a value of mode @p sm
333  * into mode @p lm (and back to mode @p sm).
334  *
335  * So the interpretation of the values may change in the intermediate mode @p sm
336  * (for example when converting negative signed integer numbers into unsigned
337  * integers) but after a conversion back they are exactly the same value.
338  *
339  * @see smaller_mode()
340  */
341 FIRM_API int values_in_mode(const ir_mode *sm, const ir_mode *lm);
342
343 /**
344  * Returns a matching unsigned mode for a given integer signed mode.
345  * Returns NULL if no matching mode exists.
346  */
347 FIRM_API ir_mode *find_unsigned_mode(const ir_mode *mode);
348
349 /**
350  * Returns a matching signed mode for a given integer unsigned mode.
351  * Returns NULL if no matching mode exists.
352  */
353 FIRM_API ir_mode *find_signed_mode(const ir_mode *mode);
354
355 /**
356  * Returns an integer mode with 2*n bits for a given integer mode with n bits.
357  * Returns NULL if no matching mode exists.
358  */
359 FIRM_API ir_mode *find_double_bits_int_mode(const ir_mode *mode);
360
361 /**
362  * Returns non-zero if the given mode honors signed zero's, i.e.,
363  * a +0 and a -0 exists and handled differently.
364  */
365 FIRM_API int mode_honor_signed_zeros(const ir_mode *mode);
366
367 /**
368  * Returns non-zero if the given mode might overflow on unary Minus.
369  */
370 FIRM_API int mode_overflow_on_unary_Minus(const ir_mode *mode);
371
372 /**
373  * Returns non-zero if the mode has a reversed wrap-around
374  * logic, especially (a + x) - x == a.
375  * This is normally true for integer modes, not for floating
376  * point modes.
377  */
378 FIRM_API int mode_wrap_around(const ir_mode *mode);
379
380 /**
381  * Returns the signed integer equivalent mode for an reference mode.
382  */
383 FIRM_API ir_mode *get_reference_mode_signed_eq(ir_mode *mode);
384
385 /**
386  * Sets the signed integer equivalent mode for an reference mode.
387  */
388 FIRM_API void set_reference_mode_signed_eq(ir_mode *ref_mode, ir_mode *int_mode);
389
390 /**
391  * Returns the unsigned integer equivalent mode for an reference mode.
392  */
393 FIRM_API ir_mode *get_reference_mode_unsigned_eq(ir_mode *mode);
394
395 /**
396  * Sets the unsigned integer equivalent mode for an reference mode.
397  */
398 FIRM_API void set_reference_mode_unsigned_eq(ir_mode *ref_mode, ir_mode *int_mode);
399
400 /**
401  * Returns size of mantissa in bits (for float modes).
402  * Note: This is the number of bits used after the leading one. So the actual
403  * accuracy of the significand is get_mode_mantissa_size()+1. The number of bits
404  * used in the encoding depends on whether the floatingpoint mode has an implicit
405  * (ieee754) or explicit (x86_extended) encoding of the leading one.
406  */
407 FIRM_API unsigned get_mode_mantissa_size(const ir_mode *mode);
408
409 /**
410  * Returns size of exponent in bits (for float modes)
411  */
412 FIRM_API unsigned get_mode_exponent_size(const ir_mode *mode);
413
414 /**
415  * Returns non-zero if the cast from mode src to mode dst is a
416  * reinterpret cast (i.e. only the bit pattern is reinterpreted,
417  * no conversion is done)
418  */
419 FIRM_API int is_reinterpret_cast(const ir_mode *src, const ir_mode *dst);
420
421 /**
422  * Returns the primitive type matching the given mode
423  */
424 FIRM_API ir_type *get_type_for_mode(const ir_mode *mode);
425
426 /** Returns number of known modes. */
427 FIRM_API size_t ir_get_n_modes(void);
428
429 /** Returns known mode number @p num. */
430 FIRM_API ir_mode *ir_get_mode(size_t num);
431
432 /** @} */
433
434 #include "end.h"
435
436 #endif