enable Rot constant folding (why was it commented out)
[libfirm] / ir / ir / irmode_t.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irmode_t.h
4  * Purpose:     Data modes of operations -- private header.
5  * Author:      Martin Trapp, Christian Schaefer
6  * Modified by: Goetz Lindenmaier, Mathias Heil
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13
14 /**
15  * @file irmode_t.h
16  */
17
18 # ifndef _IRMODE_T_H_
19 # define _IRMODE_T_H_
20
21 # include "irmode.h"
22 # include "tv.h"
23
24 /** This struct is supposed to completely define a mode. **/
25 struct ir_mode {
26   firm_kind         kind;       /**< distinguishes this node from others */
27   modecode          code;       /**< unambiguous identifier of a mode */
28   ident             *name;      /**< Name ident of this mode */
29
30   /* ----------------------------------------------------------------------- */
31   /* On changing this struct you have to evaluate the mode_are_equal function!*/
32   mode_sort         sort;          /**< coarse classification of this mode:
33                                      int, float, reference ...
34                                      (see irmode.h) */
35   mode_arithmetic   arithmetic;    /**< different arithmetic operations possible with a mode */
36   int               size;          /**< size of the mode in Bits. */
37   int               align;         /**< mode alignment in Bits. */
38   unsigned          sign:1;        /**< signedness of this mode */
39   unsigned int      modulo_shift;  /**< number of bits a valus of this mode will be shifted */
40   unsigned          vector_elem;   /**< if this is not equal 1, this is a vector mode with
41                                         vector_elem number of elements, size contains the size
42                                         of all bits and must be dividable by vector_elem */
43
44   /* ----------------------------------------------------------------------- */
45   tarval            *min;
46   tarval            *max;
47   tarval            *null;
48   tarval            *one;
49   void              *link;      /**< To store some intermediate information */
50   const void        *tv_priv;   /**< tarval module will save private data here */
51 };
52
53 /* ------------------------------- *
54  * inline functions                *
55  * ------------------------------- */
56 extern ir_mode *mode_P_mach;
57
58 static INLINE ir_mode *
59 __get_modeP_mach(void) { return mode_P_mach; }
60
61 static INLINE void
62 __set_modeP_mach(ir_mode *p) {
63   assert(mode_is_reference(p));
64   mode_P_mach = p;
65 }
66
67 static INLINE modecode
68 __get_mode_modecode(const ir_mode *mode) { return mode->code; }
69
70 static INLINE ident *
71 __get_mode_ident(const ir_mode *mode) { return mode->name; }
72
73 static INLINE mode_sort
74 __get_mode_sort(const ir_mode* mode) { return mode->sort; }
75
76 static INLINE int
77 __get_mode_size_bits(const ir_mode *mode) { return mode->size; }
78
79 static INLINE int
80 __get_mode_size_bytes(const ir_mode *mode) {
81   int size = __get_mode_size_bits(mode);
82   if ((size & 7) != 0) return -1;
83   return size >> 3;
84 }
85
86 static INLINE int
87 __get_mode_align_bits(const ir_mode *mode) { return mode->align; }
88
89 static INLINE int
90 __get_mode_align_bytes(const ir_mode *mode) {
91   int align = __get_mode_align_bits(mode);
92   if ((align & 7) != 0) return -1;
93   return align >> 3;
94 }
95
96 static INLINE int
97 __get_mode_sign(const ir_mode *mode) { return mode->sign; }
98
99 static INLINE int
100 __get_mode_arithmetic(const ir_mode *mode) { return mode->arithmetic; }
101
102 static INLINE unsigned int
103 __get_mode_modulo_shift(const ir_mode *mode) { return mode->modulo_shift; }
104
105 static INLINE unsigned int
106 __get_mode_vector_elems(const ir_mode *mode) { return mode->vector_elem; }
107
108 static INLINE void *
109 __get_mode_link(const ir_mode *mode) { return mode->link; }
110
111 static INLINE void
112 __set_mode_link(ir_mode *mode, void *l) { mode->link = l; }
113
114 /* Functions to check, whether a modecode is signed, float, int, num, data,
115    datab or dataM. For more exact definitions read the corresponding pages
116    in the firm documentation or the followingenumeration
117
118    The set of "float" is defined as:
119    ---------------------------------
120    float = {irm_F, irm_D, irm_E}
121
122    The set of "int" is defined as:
123    -------------------------------
124    int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
125
126    The set of "num" is defined as:
127    -------------------------------
128    num   = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
129             irm_Is, irm_Iu, irm_Ls, irm_Lu}
130             = {float || int}
131
132    The set of "data" is defined as:
133    -------------------------------
134    data  = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
135             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P}
136             = {num || irm_C || irm_U || irm_P}
137
138    The set of "datab" is defined as:
139    ---------------------------------
140    datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
141             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
142             = {data || irm_b }
143
144    The set of "dataM" is defined as:
145    ---------------------------------
146    dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
147             irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
148             = {data || irm_M}
149 */
150
151 static INLINE int
152 __mode_is_signed(const ir_mode *mode) {
153   assert(mode);
154   return mode->sign;
155 }
156
157 static INLINE int
158 __mode_is_float(const ir_mode *mode) {
159   assert(mode);
160   return (__get_mode_sort(mode) == irms_float_number);
161 }
162
163 static INLINE int
164 __mode_is_int(const ir_mode *mode) {
165   assert(mode);
166   return (__get_mode_sort(mode) == irms_int_number);
167 }
168
169 static INLINE int
170 __mode_is_character(const ir_mode *mode) {
171   assert(mode);
172   return (__get_mode_sort(mode) == irms_character);
173 }
174
175 static INLINE int
176 __mode_is_reference(const ir_mode *mode) {
177   assert(mode);
178   return (__get_mode_sort(mode) == irms_reference);
179 }
180
181 static INLINE int
182 __mode_is_num(const ir_mode *mode) {
183   assert(mode);
184   return (__mode_is_int(mode) || __mode_is_float(mode));
185 }
186
187 static INLINE int
188 __mode_is_numP(const ir_mode *mode) {
189   assert(mode);
190   return (__mode_is_int(mode) || __mode_is_float(mode) || __mode_is_reference(mode));
191 }
192
193 static INLINE int
194 __mode_is_data(const ir_mode *mode) {
195   assert(mode);
196   return (__mode_is_num(mode) || __get_mode_sort(mode) == irms_character || __get_mode_sort(mode) == irms_reference);
197 }
198
199 static INLINE int
200 __mode_is_datab(const ir_mode *mode) {
201   assert(mode);
202   return (__mode_is_data(mode) || __get_mode_sort(mode) == irms_internal_boolean);
203 }
204
205 static INLINE int
206 __mode_is_dataM(const ir_mode *mode) {
207   assert(mode);
208   return (__mode_is_data(mode) || __get_mode_modecode(mode) == irm_M);
209 }
210
211 static INLINE int
212 __mode_is_float_vector(const ir_mode *mode) {
213   assert(mode);
214   return (__get_mode_sort(mode) == irms_float_number) && (__get_mode_vector_elems(mode) > 1);
215 }
216
217 static INLINE int
218 __mode_is_int_vector(const ir_mode *mode) {
219   assert(mode);
220   return (__get_mode_sort(mode) == irms_int_number) && (__get_mode_vector_elems(mode) > 1);
221 }
222
223 #define get_modeP_mach()             __get_modeP_mach()
224 #define set_modeP_mach(p)            __set_modeP_mach(p)
225 #define get_mode_modecode(mode)      __get_mode_modecode(mode)
226 #define get_mode_ident(mode)         __get_mode_ident(mode)
227 #define get_mode_sort(mode)          __get_mode_sort(mode)
228 #define get_mode_size_bits(mode)     __get_mode_size_bits(mode)
229 #define get_mode_size_bytes(mode)    __get_mode_size_bytes(mode)
230 #define get_mode_align(mode)         __get_mode_align(mode)
231 #define get_mode_sign(mode)          __get_mode_sign(mode)
232 #define get_mode_arithmetic(mode)    __get_mode_arithmetic(mode)
233 #define get_mode_modulo_shift(mode)  __get_mode_modulo_shift(mode)
234 #define get_mode_vector_elems(mode)  __get_mode_vector_elems(mode)
235 #define get_mode_link(mode)          __get_mode_link(mode)
236 #define set_mode_link(mode, l)       __set_mode_link(mode, l)
237 #define mode_is_signed(mode)         __mode_is_signed(mode)
238 #define mode_is_float(mode)          __mode_is_float(mode)
239 #define mode_is_int(mode)            __mode_is_int(mode)
240 #define mode_is_character(mode)      __mode_is_character(mode)
241 #define mode_is_reference(mode)      __mode_is_reference(mode)
242 #define mode_is_num(mode)            __mode_is_num(mode)
243 #define mode_is_numP(mode)           __mode_is_numP(mode)
244 #define mode_is_data(mode)           __mode_is_data(mode)
245 #define mode_is_datab(mode)          __mode_is_datab(mode)
246 #define mode_is_dataM(mode)          __mode_is_dataM(mode)
247 #define mode_is_float_vector(mode)   __mode_is_float_vector(mode)
248 #define mode_is_int_vector(mode)     __mode_is_int_vector(mode)
249
250 #endif /* _IRMODE_T_H_ */